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)

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

By the way, I get caught by this all the time. rake routes can be really helpful with these kind of things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.