#52 Update through Checkboxes

See how to select multiple items using checkboxes and perform an action on the selected items in this episode.
# routes.rb
map.resources :tasks, :collection => { :complete => :put }

# tasks_controller.rb
def complete
  Task.update_all(["completed_at=?", Time.now], :id => params[:task_ids])
end

<% form_tag complete_tasks_path, :method => :put do %>
  <ul>
  <% for task in @incomplete_tasks %>
    <li>
      <%= check_box_tag "task_ids[]", task.id %>
      <%= task.name %>
    </li>
  <% end %>
  </ul>
  <%= submit_tag "Mark as Complete" %>
<% end %>

你可能感兴趣的:(checkbox)