Note that there are some explanatory texts on larger screens.

plurals
  1. PObulk update objects using form in rails
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>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:</p> <pre><code>&lt;% form_for :quotes, :html =&gt; { :method =&gt; :put }, :url =&gt; {:controller =&gt; "quote", :action =&gt; "bulk_update", } do |quote_form| %&gt; &lt;% @person.quotes.each do |quote| %&gt; &lt;p&gt; &lt;% fields_for "quotes[id][]", quote do |fields| %&gt; Text.... &lt;%= fields.check_box :approved %&gt;&lt;br&gt;&lt;br&gt; &lt;% end %&gt; &lt;/p&gt; &lt;% end %&gt; &lt;%= submit_tag 'Update' %&gt; &lt;% end %&gt; </code></pre> <p>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:</p> <pre><code>def bulk_update @quote = Quote.find(params[:id]) end </code></pre> <p>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.</p> <p>I'm getting parameters that look like this:</p> <p>"quotes"=>{"id"=>{"6"=>{"approved"=>"0"}, ..</p> <p>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.</p> <p>EDIT: I found a statement called update_all, but I don't know how to selectively pass it what I need...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload