Search code examples
ruby-on-rails-3urlhelper

Using url_for (form_for) for new instances of non-activerecord models


I need such a construction:

form_for Project.new

where Project is a model, that's not inherited from AR/AM/Mongoid (inherited from Spira).

Is there some monkey-patch to make Spira models answer to url_for Project.new with correct 'http://example.org/projects'?

Now it gives an exception

No route matches {:controller=>"projects", :id=>, :action=>"show"}

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-url_for

here it's said, url_for uses persisted?, but I defined persisted? correctly in instance methods and that doesn't work.

Any ideas?


Solution

  • Is this declared in your Project class?

    extend ActiveModel::Naming
    

    I believe it facilitates route naming. Not 100% that is all you need to include, however.