0

I'm still hazy on what is the first parameter for form_for or form_tag and which one to use when. But basically I'm building a website where visitors can post concert events to the site. Event is a model. The admin can see a list of submitted events and I want each one to have a check box and then the admin can check which events he wants to approve and hit submit on the form and they all get updated. :approved is a boolean field in the Event model.

I've read this post but am not sure where they get the first parameter in for form_tag in the next to last answer.

I figured I need a new controller called EventsUpdateController. So far I have something like this but it's not quite right:

<%= form_tag events_update_path do  %>
  <% @unapproved_events.each do |event| %>
    <%= fields_for "events[]", event do |e| %>
      <tr>
        <td><%= e.check_box :approved %></td>
        <td><%= event.date.strftime('%A %B %-d') %></td>
        <td><%= event.time.strftime('%l:%M %P') %></td>
        <td><%= event.title %></td>
      </tr>
    <% end %>
  <% end %>
<% end %>
Community
  • 1
  • 1
Mike Glaz
  • 5,352
  • 8
  • 46
  • 73

1 Answers1

0

Use check_box_tag

<%= form_tag events_update_path do  %>
  <% @unapproved_events.each do |event| %>
    <tr>
      <td><%= check_box_tag "event_ids[]", event.id, :id => "event-#{event.id}" %></td>
      <td><%= event.date.strftime('%A %B %-d') %></td>
      <td><%= event.time.strftime('%l:%M %P') %></td>
      <td><%= event.title %></td>
    </tr>
  <% end %>
  <%= submit_tag "Approve" %>
<% end %>

In your controller action,

events_to_approve = Event.find(params[:event_ids])
usha
  • 28,973
  • 5
  • 72
  • 93