8

これが他の場所で尋ねられた場合は申し訳ありませんが、私はこれを理解できません。セクション、トピック、返信があるフォーラムがあります。番組のトピック ビューから返信を編集および削除しようとしています。これは構造です:

resources :sections do
  resources :topics do
    resources :replies
  end
end

そこで、rake routes を実行して、編集の返信をリンクしている場所を確認します。その edit_section_topic_reply が表示され、link_to に _path を追加します。今、これは私が理解できないものです。どのパラメータを渡していますか? そうではありませんか:

<%= link_to 'Edit', edit_section_topic_reply_path(@reply, @topic, @section) %>

ActionController::RoutingErrorTopics#showこれを行うと入ります。

No route matches {:topic_id=>#<Topic id: 2, section_id: 2, user_id: nil, subject: "subject", body: "body", created_at: "2011-03-04 08:37:37", updated_at: "2011-03-04 21:37:16">, :controller=>"replies", :action=>"edit", :section_id=>nil, :id=>#<Section id: 2, name: "Section", description: "Section Description", created_at: "2011-03-04 07:50:56", updated_at: "2011-03-04 07:50:56">}

ID を渡していないようですが、前のネスト、私の新しいトピックは正常に動作します

new_section_topic_reply_path(@topic, @section)
4

3 に答える 3

14

link_to私はヘルパーのこの側面が本当に嫌いです。コードを読みやすくし、エラーを起こしにくくするために、渡す ID を明示することをお勧めします。

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

でパラメーターが順不同であるため、あまりにも多くの微妙で一見非常識なバグに遭遇しましたlink_to

于 2011-03-05T00:10:42.960 に答える
0

正しい順序は次のとおりです。

<%= link_to 'Edit', edit_section_topic_reply_path(@section, @topic, @reply) %>
于 2014-04-26T15:38:28.807 に答える