HM1
HM1

Reputation: 1684

Rails3+Devise+Simple_form: Singular resource & simple_form_for errors in path helper

Got 2 questions:

  1. 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 the simple_form_for line. foo_object_path has a valid path but it seems simple_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.

  2. 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.

Upvotes: 1

Views: 2062

Answers (1)

Vasiliy Ermolovich
Vasiliy Ermolovich

Reputation: 24617

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

Upvotes: 6

Related Questions