Redmine 添加自定义选择框
Redmine Adding Custom Selection Box
我已经开始为 redmine 开发一个插件,它允许我为问题分配 Quickbooks Online (QBO) 联系人。
我为联系人创建了一个 table,它只存储每个 qbo 联系人的姓名。
我还添加了迁移以将 qbo_contact 的参考添加到问题
class UpdateIssues < ActiveRecord::Migration
def change
add_reference :issues, :qbo_customer, index: true
end
end
我遇到的问题是,在编辑问题时,用户可以 select QBO 联系人。当用户保存问题时,Issues.qbo_contact_id 不会更新。
我觉得可能跟形式有关select离子盒
请指教
class QboHookListener < Redmine::Hook::ViewListener
# Edit Issue Form
# Show a dropdown for quickbooks contacts
def view_issues_form_details_bottom(context={})
selected = ""
# Check to see if there is a quickbooks user attached to the issue
if not context[:issue].qbo_customer_id.nil? then
selected = QboCustomers.find_by_id(context[:issue].qbo_customer_id).name
end
# Generate the drop down list of quickbooks contacts
select = context[:form].select :qbo_customer_id, QboCustomers.all.pluck(:name, :id), include_blank: true, selected: selected
return "<p>#{select}</p>"
#TODO save selection to Issues.qbp_customer_id
end
end
如果您需要更多,我已经在 github
上分享了我的工作
问题是有一个 white/black 问题允许的属性列表。
原来这是一个记录的问题 here
Fixed in r4491. You can now extend safe attributes for a given model
using:
Issue.safe_attributes 'foo', 'bar'
or makes safe attributes conditional:
Issue.safe_attributes 'foo', 'bar', :if => lambda {|issue, user|
issue.author == user}
You can have a look at redmine/safe_attributes.rb.
我只是将以下内容添加到 init.rb 以允许我的插件将 qbo_customer_id 添加到安全属性列表。
# Add qbo_customer to the safe Issue Attributes list
Issue.safe_attributes 'qbo_customer_id'
我已经开始为 redmine 开发一个插件,它允许我为问题分配 Quickbooks Online (QBO) 联系人。
我为联系人创建了一个 table,它只存储每个 qbo 联系人的姓名。
我还添加了迁移以将 qbo_contact 的参考添加到问题
class UpdateIssues < ActiveRecord::Migration
def change
add_reference :issues, :qbo_customer, index: true
end
end
我遇到的问题是,在编辑问题时,用户可以 select QBO 联系人。当用户保存问题时,Issues.qbo_contact_id 不会更新。
我觉得可能跟形式有关select离子盒
请指教
class QboHookListener < Redmine::Hook::ViewListener
# Edit Issue Form
# Show a dropdown for quickbooks contacts
def view_issues_form_details_bottom(context={})
selected = ""
# Check to see if there is a quickbooks user attached to the issue
if not context[:issue].qbo_customer_id.nil? then
selected = QboCustomers.find_by_id(context[:issue].qbo_customer_id).name
end
# Generate the drop down list of quickbooks contacts
select = context[:form].select :qbo_customer_id, QboCustomers.all.pluck(:name, :id), include_blank: true, selected: selected
return "<p>#{select}</p>"
#TODO save selection to Issues.qbp_customer_id
end
end
如果您需要更多,我已经在 github
上分享了我的工作问题是有一个 white/black 问题允许的属性列表。
原来这是一个记录的问题 here
Fixed in r4491. You can now extend safe attributes for a given model using:
Issue.safe_attributes 'foo', 'bar'
or makes safe attributes conditional:
Issue.safe_attributes 'foo', 'bar', :if => lambda {|issue, user| issue.author == user}
You can have a look at redmine/safe_attributes.rb.
我只是将以下内容添加到 init.rb 以允许我的插件将 qbo_customer_id 添加到安全属性列表。
# Add qbo_customer to the safe Issue Attributes list
Issue.safe_attributes 'qbo_customer_id'