3

I have this in my view:

form_for [:support, @thread, @reply], url: support_thread_replies_path do |f|

And this in my routes.rb:

namespace :support do
  resources :threads do
    resources :replies
  end
end

That doesn't work:

Routing Error

No route matches {:action=>"new", :controller=>"support/replies"}

If I remove the url: key from my form_for, I just get a NoMethodError when the form helper tries to call an undefined path helper method:

I get the same Routing Error even when I remove the :support symbol from the beginning of the array in my sample view code (using :support was suggested by an answer to another similar question here)

Community
  • 1
  • 1

1 Answers1

4

Pass an instance of Thread as the first parameter in the path helper:

support_thread_replies_path(@thread)

That way Rails knows what thread you're creating a new reply for.

I believe you should be able to do this without the :url key or the path helper at all, though.

clem
  • 3,524
  • 3
  • 25
  • 41
  • 2
    By the way, I get caught by this all the time. `rake routes` can be really helpful with these kind of things. – clem Nov 18 '11 at 07:40