title: Setting an object attribute from a hidden field Ruby on Rails
body: <p>I'm trying to update an <code>Idea</code> attribute <code>challenge_id</code> through a hidden form field. Here is the field:</p>
  
  <p><code>&lt;%= f.hidden_field :challenge_id, :value =&gt; @challenge.id %&gt;</code></p>
  
  <p>It successfully passes the challenge id as a param when an idea is created to the Idea Controller#create method:</p>
  
  <p><code>Started POST "/ideas.js" for ::1 at 2015-06-18 15:39:49 -0400
  Processing by IdeasController#create as JS
    Parameters: {"utf8"=&gt;"✓", "idea"=&gt;{"title"=&gt;"adsf", "description"=&gt;"asf", "domain_tokens"=&gt;"20", "challenge_id"=&gt;"5"}, "commit"=&gt;"Create Idea"}</code></p>
  
  <p>This <code>challenge_id =&gt; 5</code> should then be saved to the idea in the line <code>@idea = Idea.new(idea_params)</code> below:</p>
  
  <p><strong>ideas_controller.rb</strong></p>
  
  <pre><code>def create
      @idea = Idea.new(idea_params)
  
      respond_to do |format|
        if @idea.save
          idea_count = @idea.user.ideas_created_count
          @idea.user.update(:ideas_created_count =&gt; idea_count + 1)
          @idea.domains.each do |domain|
            current_user.add_points(1, category: domain.title)
          end
          @ideas = current_user.current_team.ideas.sort_by{|i| i.heat_index}.reverse
          @ideas = @ideas.paginate(:page =&gt; params[:ideas_page], :per_page =&gt; 10)
          format.html { redirect_to :back, notice: 'Idea was successfully created.' }
          format.json { render :show, status: :created, location: @idea }
          format.js
        else
          format.html { redirect_to :back, notice: "You must attach domains to your Idea." }
          format.json { render json: @idea.errors, status: :unprocessable_entity }
          format.js { render :create_failed }
        end
      end
    end
    .
    .
    def idea_params
     params.require(:idea).permit(:title, :description, :challenge_id)
    end
  </code></pre>
  
  <p>However, this challenge id isn't being saved to the <code>idea</code> with the other permitted <code>idea_params</code>, <code>:title</code> and <code>:description</code>.  How can I get <code>challenge_id</code> to be saved to the Idea when it's created?</p>