为什么这些默认情况下不添加到投资组合扩展中的答案是,投资组合背后的核心团队没有发现它们有用的案例。我们依靠补丁来改进或添加确实遇到这种需求的人的功能。 an open issue 目前还没有人真正想出解决方案。
至于实现本身;要覆盖您要覆盖的文件,您必须使用任务“bundle exec rake refinery:override”(using this post as reference),如下所示:
bundle exec rake refinery:override view=portfolio/_main_image
bundle exec rake refinery:override view=portfolio/show
这会将模板放在 app/views/portfolio/ 中,以便您可以修改其内容。
您还必须将迁移语法从 rails 2 更改为 rails 3,因此不是“script/generate”而是“rails generate”。
由于图像扩展默认使用“attr_accessible”以确保安全,因此您必须在 config/application.rb 之类的地方使用以下代码:
# Make the title and body fields added to Image accessible for mass assignment
config.to_prepare do
Image.send :attr_accessible, :title
Image.send :attr_accessible, :body
end
如果您想澄清这些,或者我没有完全满意地回答您的问题,请告诉我,我会详细说明。
编辑:
如果您想覆盖图像的后端视图,只需遵循相同的过程,但对于后端视图:
bundle exec rake refinery:override view=admin/images/_form
现在只需添加相同格式的字段:
<div class='field'>
<%= f.label :title %>
<%= f.text_field :title %>
</div>
<div class='field'>
<%= f.label :body %>
<%= f.text_area :body, :class => 'wymeditor widest' %>
</div>
因为您已经添加了 attr_accessible 代码,所以它会很好地保存。
如果这不是你想要的,请告诉我。
菲尔