I have a person model and a quotes model. Each person can have many quotes associated with them, which in turn has things like Author, Text, Url associated with them. In practice really only one person has a quotes object but all people could potentially have one.
I'm trying to have a dirt simple bulk moderate tool on quotes. As in, users can type in quotes and an admin can go and have all of the quotes of a particular person (but like in practice, only one will have them) and check a box which sets a boolean approved to 0 or 1. When the quotes are actually displayed, they're filtered by this field.
I'm getting really mixed up trying to create a form that updates these all in bulk. I got the form to display all of them as so:
<% form_for :quotes, :html => { :method => :put }, :url => {:controller => "quote", :action => "bulk_update", } do |quote_form| %>
<% @person.quotes.each do |quote| %>
<p>
<% fields_for "quotes[id][]", quote do |fields| %>
Text....
<%= fields.check_box :approved %><br><br>
<% end %>
</p>
<% end %>
<%= submit_tag 'Update' %>
<% end %>
I just have an incredibly generic thing in my bulk update controller which is basically like a normal update controller. I'm not sure what to put in there. I could try to put all the quotes which I probably should but I don't know how to get to that variable anyway because I'm doing all of this from whithin the Person view etc. The controller is osmething like this:
def bulk_update
@quote = Quote.find(params[:id])
end
I guess I'm getting confused about the ID that should be in there and what should be getting passed in. Should the person ID be part of this at all? Like I said, I don't really care if technically all quotes are displayed on that page, they don't need to be sorted by user.
I'm getting parameters that look like this:
"quotes"=>{"id"=>{"6"=>{"approved"=>"0"}, ..
but it complains about not finding a quote without an ID. I don't care about the ID since I want to bulk update all of them. It seems like this particular stucture would map several ids, but maybe (probably) i have to change my controller to compensate for that, not sure how though. It also doesn't work when I try to remove the quotes par tof the hash and just have"id"=>{"6"=>{"approved"=>"0"}, .. as my parameters.
EDIT: I found a statement called update_all, but I don't know how to selectively pass it what I need...