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

喜夏-厌秋 提交于 2019-12-13 03:44:55

问题


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.


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!