【发布时间】:2014-10-21 15:10:18
【问题描述】:
我开始开发一个简单的 Redmine 插件,允许用户编辑和保存特定的 Redmine 问题自定义字段。我对 Rails 和编写 Redmine 插件完全陌生,所以如果这是一个非常简单且容易回答的问题,请原谅。
到目前为止,我所拥有的是一个表格,其中显示了给定产品和版本的问题,以及其他自定义字段。请在此处查看图片:
我想做的是更改自定义字段“注释说明”(在文本区域内),当我点击“保存更改”时,我想向控制器发送一个包含所有字段的哈希表单(包括问题 ID 和问题说明说明),只要单击给定行的复选框。然后,控制器将接收给定问题编号的新描述,并使用用户输入的新字符串更新问题字段“Note description”。
这里是相关代码sn-ps。
index.html.erb:
<h3>Changelog</h3>
<table>
<%= form_tag(controller: "polls", action: "save", method: "get",
project_id: @project, id: @version_selected_combo) do %>
<tr>
<th class="checkbox"></th>
<th class="tracker">Tracker</th>
<th class="issue">Issue ID</th>
<th class="status">Status</th>
<th class="description">Note Description</th>
<th class="subject">Subject</th>
</tr>
<% @improvement_issues.each_with_index do |issue, index| %>
<tr>
<td class="checkbox"><%= check_box_tag 'issue_checkbox' %></td>
<td class="tracker"><font color="LimeGreen">
<%= issue.to_s.split(' ').at(0) %></font></td>
<td class="issue">
<%= label_tag(:issue_id, issue.to_s.split(' ').at(1)[1..-2]) %></td>
<td class="status"><%= @improvement_issues_descriptions[index] %></td>
<td class="description">
<%= text_area_tag(:transfer_note_description,
@transfer_notes_descriptions[index],
:cols => "100", :rows => "1") %></td>
<td class="subject"><%= sanitize issue.to_s.partition(': ')[2] %></td>
</tr>
<% end %>
<tr>
<td><%= submit_tag("Save changes") %></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<% end %>
</table>
如您所见,我在表格中使用表单助手,我不知道这是否是正确或更好的方法。
polls_controller.rb:
def save
p params
end
这只是点击“保存更改”按钮后调用的方法。
如果我选中两个复选框,我得到的日志如下:
[ 2014-10-21 15:55:21.2754 21609/7f0234d4e700 Pool2/Implementation.cpp:1291 ]: [App 21695 stdout] {"utf8"=>"✓", "issue_checkbox"=>"1", "transfer_note_description"=>"description for the note here", "commit"=>"Save changes", "id"=>"trunk", "method"=>"get", "project_id"=>"sandbox", "action"=>"save", "controller"=>"polls"}
我无法向控制器发送注释说明和问题编号。
我没有模型,因为我不需要模型,因为所有数据都已经在 redmine 数据库中。当用户提交表单时,我希望控制器获取带有问题编号和问题说明描述的哈希。
我想尽可能多地使用rails,因此,如果可以避免的话,我不想使用javascript。
欢迎任何帮助。提前感谢您的宝贵时间。
【问题讨论】:
标签: ruby-on-rails redmine redmine-plugins