title: Pass values from select_tag in params
body: <p>I created a "select_tag" field and I need it when the user clicks save all the values of this field to be passed by params to the controller. The problem is that when I click save, only the first value entered in this field is passed to the controller.</p>
  
  <p>To better understand, the "select_tag" field is populated through another field, the "f.text_field :members" field. When I click on an "add" button the value of the "f.text_field :members" field is passed to the "select_tag" field and so I want to be able to check all these values from the "select_tag" field to validate and save, how do I do that? As I already said, only the first value entered is passed.</p>
  
  <p>Looking at the params now, I realized that the value that returns as "params" is just the value that is selected in the dropdown, the other values are not considered. How do I pass all values in the dropdown?</p>
  
  <p>Code:</p>
  
  <pre><code>&lt;%= form_for(@focus_group) do |f| %&gt;
    &lt;% if @focus_group.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@focus_group.errors.count, "error") %&gt; prohibited this focus_group from being saved:&lt;/h2&gt;
  
        &lt;ul&gt;
        &lt;% @focus_group.errors.full_messages.each do |message| %&gt;
          &lt;li&gt;&lt;%= message %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
    &lt;script type="text/javascript"&gt;
    $(function() {
      $('#focus_group_moderator, #focus_group_members').autocomplete({
        source: '/focus_groups/autocomplete.json'
      });
    });
    function add(){
      var value = $('#focus_group_members').val();
      var select = document.getElementById("membersAdded");
      var option = document.createElement("option");
      option.text = value;
      option.value = value;
      select.add(option);
  
      $('#focus_group_members').val("");
    }
  
    function removeFromSelect(){
      var select = document.getElementById("membersAdded");
      select.remove(select.selectedIndex);
    }
    &lt;/script&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :name %&gt;&lt;br&gt;
      &lt;%= f.text_field :name %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :topic %&gt;&lt;br&gt;
      &lt;%= f.text_field :topic %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :moderator %&gt;&lt;br&gt;
      &lt;%= f.text_field :moderator %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :description %&gt;&lt;br&gt;
      &lt;%= f.text_area :description %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :members %&gt;&lt;br&gt;
      &lt;%= f.text_field :members %&gt;
      &lt;input onclick="add()" type="button" value="Add" /&gt;&lt;br&gt;
      &lt;%= select_tag(:membersAdded, options_for_select([])) %&gt;
      &lt;input onclick="removeFromSelect()" type="button" value="Remove" /&gt;&lt;br&gt;
      &lt;br&gt;
    &lt;/div&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>CONTROLLER</p>
  
  <pre><code>class FocusGroupsController &lt; ApplicationController
    before_action :set_focus_group, only: [:show, :edit, :update, :destroy]
    include FocusGroupsHelper
  
    def index
      if(params[:term])
        @profile = Profile.all.select("name", "id")
  
        @lista = Array.new
  
        @profile.each do |x|
          @lista.push(x.name)
        end
  
        respond_to do |format|
          format.html
          format.json { render json: @lista.to_json}
        end
      else
        @focus_groups = FocusGroup.all
      end
    end
  
    def show
    end
  
    def new
      @focus_group = FocusGroup.new
      @membersAdded
  
      respond_to do |format|
        format.html
        format.json { render json: Profile.all.to_json}
      end
    end
  
    def edit
    end
  
    def create
      @moderator= find_profiles_id(focus_group_params[:moderator])
      @moderator.each do |f|
        @moderator_id = f.id
      end
  
      @params = focus_group_params
      @params[:moderator] = @moderator_id
  
      @focus_group = FocusGroup.new(@params)
  
      if @focus_group.save
        redirect_to @focus_group, notice: 'Focus group was successfully created.'
      else
        render :new
      end
    end
  
    def update
      if @focus_group.update(focus_group_params)
        redirect_to @focus_group, notice: 'Focus group was successfully updated.'
      else
        render :edit
      end
    end
  
    def destroy
      @focus_group.destroy
      redirect_to focus_groups_url, notice: 'Focus group was successfully destroyed.'
    end
  
    def autocomplete
      if(params[:term])
        @profile = Profile.all.where("user_id &lt;&gt; 0 and is_template = 'f' and name LIKE ?", "#{params[:term]}%").select("name", "id")
  
        @lista = Array.new
  
        @profile.each do |x|
          @lista.push(x.name)
        end
  
        respond_to do |format|
          format.html
          format.json { render json: @lista.to_json}
        end
      end
    end
  
    def find_profiles_id(name)
      return Profile.all.where("name LIKE ?", "#{name}%").select("id")
    end
  
    def find_profiles_name(id)
      @profile = Profile.all.where("id = ?", "#{id}").select("name")
  
      @profile.each do |e|
        @name = e.name
      end
      return @name
    end
  
    private
  
      def set_focus_group
        @focus_group = FocusGroup.find(params[:id])
      end
  
      def focus_group_params
        params.require(:focus_group).permit(:name, :topic, :moderator, :description, :members, :membersAdded)
      end
  end
  </code></pre>