Ruby on Rails Sunday, September 5, 2010

Kelp Kelp wrote:
> Fernando Perez wrote:
>> You almost have it all correct, just in your view:
>>
>> <%= form_for([@article, @comment]) do |f| %>
>>
>>
>> --
>>
>> http://digiprof.tv
>
> That worked excellently.
>
> I have one more question about the same set of files. I want to add a
> link for editing the comments on the article show page, but I am getting
> an error.
> This is the code I am using to display the edit comment link:
> <%= link_to "Edit Comment", edit_comment_path(comment) %>
>
> Here is the error I get:
> undefined method `edit_comment_path' for #<#<Class:0xa2f2c90>:0xa2f04f4>
>
> I think the reason I get the error is that I am using the code in the
> article show page, which is in the article controller, and so there is
> no predefined path to 'edit_comment_path'. Is there a way to access the
> path inside of article and send the object 'comment' to it?


Okay, I found out that I should be using
edit_article_comment_path(comment) to compensate for the comment
resource being inside the article resource.

But my edit link goes to:
http://localhost:3000/articles/320/comments/297/edit, when it should go
to http://localhost:3000/articles/297/comments/320/edit.

The ID's are reversed for some reason. Here is the edit method of the
comments controller:
def edit
@comment = Comment.find(params[:id])
@article = Article.find(params[:article_id])
@title = "Edit Comment"
end
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment