Rails3 + Devise + Simple_form:Singular resource& simple_form_for路径助手中的错误 [英] Rails3+Devise+Simple_form: Singular resource & simple_form_for errors in path helper

查看:219
本文介绍了Rails3 + Devise + Simple_form:Singular resource& simple_form_for路径助手中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个问题:


  1. 如何让simple_form_for使用与...相关联的奇异资源:foo_object:users (见下面的代码摘录)?我在 simple_form_for foo_objects_path @foo c>行。 foo_object_path 有一个有效的路径,但似乎 simple_form_for 正在使用复数版本。我已经google'd&阅读有关单一资源和路径问题的SO帖子,但尚未找到解决方案。

  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.

我需要创建一个嵌套资源:foo_object,因为它关联到:用户?如果是,那么它会与Devise的用户模型发生冲突吗?

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?

路线:

devise_for :users  
resource :foo_object

型号:

:user is the Devise User's model and has_one :foo_object  
:foo_object belongs_to :user

查看(haml):(更新6/27/13:更正为=从 - )

View (haml): (update 6/27/13: corrected to = from -)

= simple_form_for @foo do |f|
    = f.input :firstname
    = f.input :lastname
    = f.button :submit

希望很清楚。谢谢。

推荐答案

一个注释在关于这个的指南。这是一个解决方法:

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

这篇关于Rails3 + Devise + Simple_form:Singular resource& simple_form_for路径助手中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆