问题
Got 2 questions:
How can I get the simple_form_for to work with singular resource :foo_object that's associated to :users (see code excerpts below)? I get NoMethodError: undefined method
foo_objects_path
for@foo
in thesimple_form_for
line.foo_object_path
has a valid path but it seemssimple_form_for
is using the plural version. I've google'd & read SO posts regarding singular resource and path issues, but haven't found a solution to this.Do I need to create a nested resource for :foo_object since it's associated to :user? If yes, then will it conflict with Devise's User model?
Routes:
devise_for :users
resource :foo_object
Model:
:user is the Devise User's model and has_one :foo_object
:foo_object belongs_to :user
View (haml): (update 6/27/13: corrected to = from -)
= simple_form_for @foo do |f|
= f.input :firstname
= f.input :lastname
= f.button :submit
Hope it's clear. Thanks.
回答1:
There is a note in guides about this. Here's a workaround:
= simple_form_for @foo, url: foo_object_path do |f|
= f.input :firstname
= f.input :lastname
= f.button :submit
来源:https://stackoverflow.com/questions/17336533/rails3devisesimple-form-singular-resource-simple-form-for-errors-in-path-he