1

私の見解ではこれがあります:

<%= form_for @comment, :as => :post, :url => user_ticket_message_comments_path, :html => { :class => "add-comment", :id => "add-comment-" + @ticket.id.to_s } do |f| %>
  <%= f.label :body, "Add comment" %>
  <%= f.text_area :body %>
  <%= f.submit "Add comment" %>
<% end %>

私のroutes.rbで:

resources :users do
  resources :tickets do
    resources :messages do
      resources :comments
    end
  end
end

ルーティングエラーが発生します:

No route matches {:controller=>"comments"}

4

1 に答える 1

4

ユーザー、チケット、メッセージが欠落しているようです:

user_ticket_message_comments_path(@user, @ticket, @message)

生成される URL は次のようになるため、これらのパラメーターが必要です。

/users/:user_id/tickets/:ticket_id/messages/:message_id/comments

引数がなければ、Rails はその URL を生成する方法を知りません。

また、Rails アプリの経験則では、「リソースを 1 レベル以上ネストしてはならない」ということを考慮してください。

Jamis Buck によるこの投稿では、リソースを任意にネストする代わりに、次のように 1 つのレベルのネストのみを使用することを提案しています。

resources :users do
  resources :tickets
end

resources :tickets do
  resources :messages
end

resources :messages do
  resources :comments
end
于 2012-05-09T23:01:03.617 に答える