Platinum Partner

Rails Update Multiple Records With One Form Action

// reports table has 3 columns: "name", "pub_date" and a boolean field "current"
//
// i want to display all records (or subset) in a form and modify the columns for each field at will...
//
// app/controllers/reports_controller.rb:


  def index
    @reports = Report.find_all_by_current(1)
  end

  def edit_reports
    @reports = Report.find(:all)
  end
  
  def update_reports
    Report.update(params[:report].keys, params[:report].values)
    flash[:notice] = 'Reports were successfully updated.'
    redirect_to :action => "index"
  end


// app/views/reports/index.html.erb:



  <% @reports.each do |report| %>
    
  <% end %>
Current Publication date Name
<%=h report.current %> <%=h report.pub_date %> <%=h report.name %>
<%= link_to 'edit', :action => "edit_reports" %>
// app/views/reports/edit_reports.html.erb: <% form_for :report, :url => {:action => 'update_reports'} do -%> <% @reports.each do |report| %> <% fields_for "report[]", report do |report_fields| %> <% end %> <% end %>
Current Publication date Name
<%= report_fields.check_box :current %> <%= report_fields.date_select :pub_date %> <%= report_fields.text_field :name %>
<%= submit_tag 'Update' %> <% end %>
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}