I am trying to add comments to my blog.
comments_controller.rb: def create @blog = Blog.find(params[:blog_id]) @comment = @blog.comments.create(params[:comment]) redirect_to blog_path(@blog) end
In my blog's index view: <% form_for([ @blog, @comment ]) do |f| %> ... <% end %>
blog.rb: has_many :comments
comment.rb: belongs_to :blog
routes.rb: map.resources :blogs, :has_many => :comments
The error I get is: undefined method 'nil_class_path' and it points to the form_for line
I can add comments from the console, but if I attempt to view them by adding "@comments = Blog.comments.all" to my blog_controller's index action, then "<% @comments.each do |comment| %> " into the corresponding view, I get an "undefined method 'comments'" error
Any assistance would be awesome. And I am only using rails 2 because my host does not support rails 3. I do not have any trouble getting the above to work in rails 3, but i don't know what I am doing wrong now.
Thanks.