Can you change something in this kind of relationship, because it works great in previous version? NameError (uninitialized constant User::Post) class Post < ActiveRecord::Base belongs_to :user ... class User < ActiveRecord::Base has_many :posts accepts_nested_attributes_for :posts ... class PagesController < ApplicationController def index @user = User.find(6) @posts = @user.posts #############ERROR end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Please ask this question on Rubyonrails-talk. It seems like you are defining your Post model in a file incorrectly named / located. On 13/07/2011, at 22:04, M Bougie <mathieub@socialship.net> wrote:> Can you change something in this kind of relationship, because it > works great in previous version? > > NameError (uninitialized constant User::Post) > > class Post < ActiveRecord::Base > belongs_to :user > ... > > class User < ActiveRecord::Base > has_many :posts > accepts_nested_attributes_for :posts > ... > > class PagesController < ApplicationController > def index > @user = User.find(6) > @posts = @user.posts #############ERROR > end > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Thank you for your reply The code I gave you worked with 3.0.9. RAILS_ROOT/app/models/post.rb RAILS_ROOT/app/models/user.rb RAILS_ROOT/app/controllers/pages_controller.rb I have difficulty when i specify @foo.first.key instead of @foo[0].key too. ...All my files kept their names from previous versions, but rails 3.1.0.rc4 complain. If you have an idea I''ll take it, otherwise I''ll try on Rubyonrails- talk.... On Jul 13, 5:47 pm, Ryan Bigg <radarliste...@gmail.com> wrote:> Please ask this question on Rubyonrails-talk. It seems like you are defining your Post model in a file incorrectly named / located. > > On 13/07/2011, at 22:04, M Bougie <mathi...@socialship.net> wrote: > > > Can you change something in this kind of relationship, because it > > works great in previous version? > > > NameError (uninitialized constant User::Post) > > > class Post < ActiveRecord::Base > > belongs_to :user > > ... > > > class User < ActiveRecord::Base > > has_many :posts > > accepts_nested_attributes_for :posts > > ... > > > class PagesController < ApplicationController > > def index > > @user = User.find(6) > > @posts = @user.posts #############ERROR > > end > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > > To post to this group, send email to rubyonrails-core@googlegroups.com. > > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-core?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Apparently Analagous Threads
- warning: toplevel constant XYZ referenced Admin:XYZ
- root_path and root_url undefined
- Undefined method error
- Dashboard throwing undefined method `to_time' for nil:NilClass error on page view
- subdomain based namespacing makes RSpec incorrectly state that the route doesn't exist