为什么这些默认情况下没有添加到投资组合扩展中的答案是投资组合背后的核心团队没有发现它们有用的案例。我们依靠补丁来改进或添加确实遇到这种需求的人的功能。有一个悬而未决的问题,目前还没有人真正想出解决方案。
至于实现本身;要覆盖您想要覆盖的文件,您必须使用任务“bundle exec rake refinery:override”(使用这篇文章作为参考),如下所示:
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 代码,所以它会保存得很好。
如果这不是你想要的,请告诉我。
菲尔