Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on Rails - How to use a select box to change an attribute of the selected items?
    primarykey
    data
    text
    <p>I'll start off with a bit of context to my question. I have a group of offices which each have reviewers associated with them. A reviewer can only be associated with one office. I want to create two select boxes. One lists all of the reviewers that are associated with the office I am viewing, the other lists all of the reviewers that are available (which is basically all of the reviewers that aren't already assigned to this office).</p> <p>The goal of the current reviewer's listbox is to set their office to nil when they are selected. The goal of the available reviewers listbox is to set their office to this office's id when they are selected. I'm not sure how to change only the reviewers' office_id when using a select box. </p> <p>Code-wise, what I have so far is this:</p> <p><strong>office_controller.rb</strong></p> <pre><code>def edit @office = Group.find params[:id] if params[:id] @current_reviewers = Reviewer.find_all_by_group_id(@office.id) @available_reviewers = Reviewer.where('group_id &lt;&gt; ?',[@office.id]) end def update ? end </code></pre> <p><strong>office/edit.html.erb</strong></p> <pre><code>&lt;% form_for(@office, :url =&gt; {:controller =&gt; :office, :action =&gt; :update, :id =&gt; @office.id}, :html =&gt; {}) do |f| %&gt; ... &lt;%= select_tag 'removedReviewers', options_from_collection_for_select(@current_reviewers, "id", "display_name"), :multiple =&gt; true %&gt; &lt;%= select_tag 'chosenReviewers', options_from_collection_for_select(@available_reviewers, "id", "display_name"), :multiple =&gt; true %&gt; ... &lt;% end %&gt; </code></pre> <p>Any suggestions would be greatly appreciated. Thanks!</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.
    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