Reputation: 1163
The problem: I have a collection of people, I want to have a revise.html page that allows me to increment a integer on all the people.
if I make a new method in the people_controller it auto sends me to people/revise.. which gets interpreted as show/revise... which is not an id.
I understand this happens because of REST constrictions. But I dont really get how I should be doing this update to all the records.
Am I to make a new controller for the revision revisement? or do I modifie the update method inside of the people_controller.
here is some code for my revise.html.erb:
<h1>Update the All Bio's Revision'</h1>
<% form_for(@people) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :version %><br />
<%= f.text_field :version %>
</p>
<p>
<%= f.submit "Update Revision" %>
</p>
<% end %>
<%= link_to 'Back', people_path %>
I want this to then submit its param from the text field and update all the people
@people = Person.find(:all)
@people.each do |person|
person.version = params(:version)
end
Yeah I just dont know if I am getting this new syntax of rails 2 and such.
Thanks for any help everyone!
Upvotes: 0
Views: 166
Reputation: 31756
If it is something that happens on a collection of people, then it belongs in the people controller. You can define a route to a collection of people by modifying your resource like this:
map.resources :people, :collection => { :revise => :post }
docs for adding a collection to your route
Upvotes: 2
Reputation: 26
So you're retrieving all posts then setting the version attribute on them one by one (and forgetting to save them). You'd be better off using Person.update_all. Let the database do the work for you.
As for the controller action, there's no harm in adding an additional action to the standard RESTful seven, as long as you don't go crazy with it. It just means that "revise" becomes like a reserved keyword; no person can ever have that as his/her ID. You could also just stick the form down the bottom of your "index" action.
Upvotes: 1