Skip to content

Instantly share code, notes, and snippets.

@chewmanfoo
Created March 2, 2011 20:11
Show Gist options
  • Select an option

  • Save chewmanfoo/851643 to your computer and use it in GitHub Desktop.

Select an option

Save chewmanfoo/851643 to your computer and use it in GitHub Desktop.
CONTROLLER:
def edit_multiple
@on_calls = OnCall.find(params[:on_call_ids])
end
def update_multiple
@on_calls = OnCall.find(params[:on_call_ids])
@on_calls.each do |on_call|
on_call.update_attributes!(params[:on_call].reject {|k,v| v.blank?})
end
flash[:notice] = "Uddated on call scheduling!"
redirect_to on_calls_path
end
================================================================
VIEW:
<% title "Create On Call Schedule" %>
<p>
<em>Note:</em> Either administer your team's on call schedule here, n shifts at a time, or create on_call records in the on_call object directly (<%= link_to "here", on_calls_path %>). You should not do both.
</p>
<p>
For the <%= @team.name %> Team, each on call shift is <%= @team.shift_length %>. You will be configuring <%= @team.plan_length %> shfts for each specialization in your team. To change these values, edit the On Call team record, <%=link_to "here", @team %>.
</p>
<% form_tag edit_multiple_on_calls_path do %>
<table>
<tr><th>Name</th><th>Start Date<br />(after 8:00am)</th><th>End Date<br />(until 8:00am)</th><th>Engineer</th></tr>
<% for o in @on_calls %>
<% fields_for "on_calls[]", o do |f| %>
<tr>
<td><%= link_to o.name, o %></td>
<td><%= o.start_date %></td>
<td><%= o.end_date %></td>
<td><%= collection_select(:on_call, :engineer_id, @engineers, :id, :name, {:prompt => true}) %></td>
<% end %>
<% end %>
</table>
<p><%= submit_tag "Submit" %></p>
<% end %>
=================================================================
ERROR:
Processing OnCallsController#edit_multiple (for 172.25.50.65 at 2011-03-02 14:47:15) [POST]
Parameters: {"on_call"=>{"engineer_id"=>"6"}, "commit"=>"Submit", "authenticity_token"=>"secret"}
User Load (0.4ms) SELECT * FROM `users` WHERE (`users`.`id` = 2) LIMIT 1
User Columns (0.8ms) SHOW FIELDS FROM `users`
OnCallTeam Load (0.2ms) SELECT * FROM `on_call_teams`
OnCallTeam Columns (0.3ms) SHOW FIELDS FROM `on_call_teams`
ActiveRecord::RecordNotFound (Couldn't find OnCall without an ID):
app/controllers/on_calls_controller.rb:60:in `edit_multiple'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment