通过插件补丁给Project模块添加属性
Adding attributes to Project module through plugin patch
我正在尝试在 redmine 中创建补丁以添加项目特定的电子邮件 header 和外发电子邮件的电子邮件页脚。我查看了几个示例并设法得到了一些东西 运行,但是每当我单击 'Save' 它会闪烁 'success' 通知并且永远不会更新数据库。日志文件中没有报告任何错误,firebug 中的一切看起来都很正常(据我所知)。
吸气剂工作得很好,当我手动修改数据库记录时,更改会反映出来,所以我知道我的 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
app/views/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 %>
如有任何帮助,我们将不胜感激!提前致谢!
我正在尝试在 redmine 中创建补丁以添加项目特定的电子邮件 header 和外发电子邮件的电子邮件页脚。我查看了几个示例并设法得到了一些东西 运行,但是每当我单击 'Save' 它会闪烁 'success' 通知并且永远不会更新数据库。日志文件中没有报告任何错误,firebug 中的一切看起来都很正常(据我所知)。
吸气剂工作得很好,当我手动修改数据库记录时,更改会反映出来,所以我知道我的 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
app/views/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 %>
如有任何帮助,我们将不胜感激!提前致谢!