Friendly_id 和 ActiveScaffold 冲突
我有 friend_id 和 ActiveScaffold 为我的 Rails 应用程序安装。
因为并非所有模型都有唯一的名称字段,所以我必须使用 Slugged Model 使其发挥作用。 Friendly_id 完美地完成了这项工作我有友好的 URL,我可以使用友好的 id 加载对象。
但是当我想用 ActiveScaffold 创建一个新对象时,它显示以下错误消息:
ActiveScaffold::ReverseAssociationRequired (协会蛞蝓:为了 支持 :has_one 和 :has_many 其中 父记录是新的,子记录 记录验证的存在 父级,ActiveScaffold 需要 反向关联(belongs_to)。)
当然,我无法在该侧创建 belongs_to
关联,因为它是由 Friendly_id
模块创建的,并且应该包含每个以 sluged 方式工作的模型那里。
该模型如下所示:
class FooBar < ActiveRecord::Base
has_friendly_id :name, :use_slug => true, :approximate_ascii => true
end
在我的 ApplicationController
中:
class Admin::FooBarsController < Admin::ApplicationController
active_scaffold :foo_bar do |config|
config.list.columns = [ :id, :name ])
config.update.columns = [ :name ]
config.create.columns = config.update.columns
end
end
有办法让它工作吗?
版本:Friendly_id 3.2.0
,ActiveScaffold 是 rails-2.3
git 分支中的最新版本。
更新:看起来在生产模式下并不冲突。
I have friendly_id and ActiveScaffold installed for my Rails application.
Because not all of my models have unique name fields I have to use the Slugged Model to make it work. friendly_id does the job flawlessly I have friendly URLs and I can load the objects using the friendly id.
But when I want to create a new object with ActiveScaffold, it says the following error message:
ActiveScaffold::ReverseAssociationRequired
(Association slugs: In order to
support :has_one and :has_many where
the parent record is new and the child
record(s) validate the presence of the
parent, ActiveScaffold requires the
reverse association (the belongs_to).)
Of course I cannot create the belongs_to
association in that side because it's created by the friendly_id
module and every model which works slugged way should be included there.
The model looks like this:
class FooBar < ActiveRecord::Base
has_friendly_id :name, :use_slug => true, :approximate_ascii => true
end
In my ApplicationController
:
class Admin::FooBarsController < Admin::ApplicationController
active_scaffold :foo_bar do |config|
config.list.columns = [ :id, :name ])
config.update.columns = [ :name ]
config.create.columns = config.update.columns
end
end
Is there a way to make this work?
The versions: friendly_id 3.2.0
, ActiveScaffold latest in the rails-2.3
git branch.
UPDATE: Seems like it does not conflict in production mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调用
... 创建一个 has_many 和一个 has one 关联,指向一个 slug AR 模型,该模型没有任何多态性属于正确定义的关联。
因此,基本上,要解决此错误,您需要做的就是在父模型的控制器(具有Friendly_id内容的控制器)中定义反向关联
,并且它可以工作:-)
PS:我使用Friendly_id作为gem和ActiveScaffold VHO主分支用于导轨 3
calling
... creates a has_many and a has one associations pointing to a slug AR model which hasn't any polymorphic belongs to association properly defined.
So basically what you need to do to solve this error is to define the reverse associations in the controller of your parent model (the one who has friendly_id stuff)
and it works :-)
PS : I use friendly_id as gem and ActiveScaffold VHO master branch for rails 3
过去我也有同样的问题,我已经解决了,但我不记得我的解决方案,看看我的代码,唯一相关的黑客是使用Friendly_id作为插件,最后用environemnt.rb中的config.plugin加载它
我是不确定,抱歉,但如果您尝试,请告诉我。
对不起我的英语
In the past I have the same problem , i have solved , but i dont remember my solution , lookin at my code the only relevant hack is to use friendly_id as plugin and load it at last with config.plugin in environemnt.rb
I'M NOT SURE ,sorry, but if you try let my know.
sorry for my english to