views:

737

answers:

1

Problem

The form_for helper incorrectly determines the path to my nested resource inside of a namespace. The models in question are: Forum::Thread and Forum::Reply respectively, located in a subfolder called "forum" under my models directory. This is in Rails 3 BETA 3.

routes.rb

  namespace :forum do
    root :to => 'threads#index'
    resources :threads do
      resources :replies
    end
  end

app/views/forum/replies/_form.html.haml

...
  - form_for [@thread, @reply] do |f|
...

app/controllers/forum/replies_controller.rb

...
  def new
    @reply = Forum::Reply.new
  end
...

Error

undefined method `forum_thread_forum_replies_path'

In reference to the line outlined above in _form.html.haml

+2  A: 

I have a project with an admin namespace and People and Images resources, this is the way I build my form_for in rails3, I haven't found a way just yet to do it cleaner...

<%= form_for [@person, @image], :url => admin_person_images_path do |f| %>
Bitterzoet
Will this work for both adding and editing?
nlaq
Sure, you will just need to change the url to the update path.
Bitterzoet
Which requires that I pass in the url into my form partial... Not a big deal, but it seems that you shouldn't have to do that.
nlaq
Hmm, I started messing around with it again and now I have the following that works. form_for [:admin, @person, @image] do |f|
Bitterzoet