我正在尝试在redmine中创建一个补丁,为外发电子邮件添加项目特定的电子邮件标题和电子邮件页脚。我查看了一些示例并设法启动并运行,但每当我单击“保存”时,它会闪烁“成功”通知并且永远不会更新数据库。日志文件中没有报告错误,并且在firebug中一切看起来都正常(据我所知)。
getter工作得很好,当我手动修改数据库记录时会反映出更改,所以我知道我的includes / requires都在工作。
任何人都可以提出一个可能的罪魁祸首,为什么它不能保存我的新属性?我错过了什么吗?
LIB / project_email_patch / project_patch.rb
require_dependency 'project'
module ProjectEmailPatch
module ProjectPatch
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
attr_accessible :email_header, :email_footer
end
end
module InstanceMethods
def email_header
read_attribute(:email_header) ? read_attribute(:email_header) : Setting.emails_header
end
#def email_header=(header)
# write_attribute(:email_header, header)
#end
def email_footer
read_attribute(:email_footer) ? read_attribute(:email_footer) : Setting.emails_footer
end
#def email_footer=(footer)
# write_attribute(:email_footer, footer)
#end
end
end
end
Rails.configuration.to_prepare do
#unless Project.included_modules.include?(ProjectEmailPatch::ProjectPatch)
Project.send(:include, ProjectEmailPatch::ProjectPatch)
#end
end
应用程序/视图/ project_emails / _edit.html.erb
<table border="1">
<tr><th>Test</th><td>Hello World</td></tr>
<tr><th>Header</th><td><%= @project.email_header %></td></tr>
<tr><th>Footer</th><td><%= @project.email_footer %></td></tr>
</table>
<%= form_for(@project, :url => {:action => 'update', :id => @project}) do |f| %>
<div>
<table>
<tr>
<th><%= f.label :email_header %></th>
<td><%= f.text_area :email_header, :size => "50x10" %></td>
</tr>
<tr>
<th><%= f.label :email_footer %></th>
<td><%= f.text_area :email_footer, :size => "50x10" %></td>
</tr>
</table>
</div>
<%= f.submit "Save", :confirm => "Are you sure you are ready to submit?" %>
<% end %>
任何帮助将不胜感激!提前谢谢!