Rails 3 link_to routes (edit) nested resources

后端 未结 3 581
旧时难觅i
旧时难觅i 2021-01-05 05:18

Sorry if this has been asked elsewhere, but I can\'t figure this out. I have a forum with sections, topics, and replies. I\'m trying to edit and delete replies from the show

相关标签:
3条回答
  • 2021-01-05 05:46

    I really dislike this aspect of the link_to helper. In the interest of making your code more readable and less prone to error, I would suggest that you be explicit about which IDs you are passing in.

    <%= link_to 'Edit', edit_section_topic_reply_path(:id => @reply.id, 
                                                      :topic_id => @topic.id, 
                                                      :section_id => @section.id) %>
    

    I've run into too many subtle and seemingly insane bugs due to params being out of order in a link_to.

    0 讨论(0)
  • 2021-01-05 05:52

    One more way for edit link

    <%= link_to [:edit,@section,@topic,@reply] %>
    
    0 讨论(0)
  • 2021-01-05 06:08

    I think the right order should be:

    <%= link_to 'Edit', edit_section_topic_reply_path(@section, @topic, @reply) %>
    
    0 讨论(0)
提交回复
热议问题