-2

I am starting to develop a simple Redmine plugin that will allow a user to edit and save a specific Redmine Issue custom field. I am completely new to Rails and to writing Redmine plugins, so please excuse me if this is a very simple and easy question to answer.

What I have so far is a table which shows Issues from a given Product and Version, along with other custom fields. Please see the image here:

changelog table

What I would like to do is to change the the custom field "Note Description" (inside the text area) and when I hit the "Save changes" I would like to send the controller a hash with all the fields of this form (including Issue ID and Issue Note Description), whenever the check-box is clicked for a given row. The controller will then receive the new descriptions for a given Issue number and update the Issue field "Note description" with the new string entered by the user.

Here are the relevant code snippets.

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>

As you can see I am using a Form Helper inside a table, I don't know if this is the correct or better way to do it.

polls_controller.rb:

def save
  p params
end

This is just the method called after hitting the "Save changes" button.

The log I get if I check both check-boxes is the following:

[ 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"}

I am not being able to send the controller the note descriptions and issue numbers.

I have no model because I don't need one, as all the data is already in the redmine database. When the user submits the form I want the controller to get a hash with the issue number and the issue note description.

I want to use rails as much as possible, and as such, I don't want to use javascript if I can avoid it.

Any help will be welcome. Thanks in advance for your time.

Miguel Rentes
  • 994
  • 1
  • 10
  • 27

1 Answers1

0

I was making two mistakes:

  1. I was choosing the wrong form helpers;
  2. I was separating my form data into different table elements (although not shown in the original code snippet).

My solution was to replace the following form helpers:

  1. From checkbox_tag into check_box
  2. From label_tag into text_field_tag
  3. From text_area_tag into text_area

Making these changes, I could very easily see on the params received by the controller all the form data that the user had just changed on the view.

Also, the initial form_tag element is now outside all the table elements (I just have 1 table now), so that I can capture all the form fields the user change, like this:

<%= form_tag(controller: "polls", action: "save", project_id: @project, id: @version_selected_combo) do %>
 <table>
 (...)
 all the form elements ...
 (...)
 </table>
<% end %>
Miguel Rentes
  • 994
  • 1
  • 10
  • 27