title: Pass value via hidden_field in rails
body: <p>I am trying to implement a rating system in my app, i tried Rateit but couldnt get it to work so thought I would try and build my own, plus this way I am hoping to learn a lot more by understanding the process</p>
  <p>At the moment I am trying to pass the value of the clicked star</p>
  <h3>Form</h3>
  <pre><code>&lt;%= form_for @rating do |f| %&gt;
    &lt;%= f.hidden_field :ratings, :id =&gt; &quot;hiddenRating&quot;, :value =&gt; '' %&gt;
    &lt;%= f.hidden_field :user_id, :value =&gt; current_user.id %&gt;
    &lt;%= f.hidden_field :recipe_id, :value =&gt; @recipe.id %&gt;
    &lt;div class=&quot;ratings&quot;&gt;
      &lt;ul&gt;
        &lt;li id=&quot;firstStar&quot;&gt;&lt;/li&gt;
        &lt;li&gt;&lt;/li&gt;
        &lt;li&gt;&lt;/li&gt;
        &lt;li&gt;&lt;/li&gt;
        &lt;li&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
    &lt;%= f.submit &quot;Submit&quot; %&gt;
  &lt;% end %&gt;
  </code></pre>
  <h3>JS</h3>
  <pre><code>$(document).ready(function(){
    $('#firstStar').click(function(){
      $('#hiddenRating').value = 1;
    });
  }); 
  </code></pre>
  <p>So the idea is that if a user clicks the first star then a value of 1 should be passed as the ratings value within the form, this does not happen as I do not know what to pass within</p>
  <pre><code>:value =&gt; ''
  </code></pre>
  <p>Im sure there are much better ways to do this but as i said I want to learn piece by piece so that by the end I can put it all together, of course if someone has a better suggestion then please let me know.</p>
  <h2>Edit</h2>
  <h3>Controller</h3>
  <pre><code>def new
    @rating = Rating.new
  
    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @rating }
    end
  end
  
  def create
    @rating = Rating.new(params[:rating])
  
    respond_to do |format|
      if @rating.save
        format.html { redirect_to @rating, notice: 'Rating was successfully created.' }
        format.json { render json: @rating, status: :created, location: @rating }
      else
        format.html { render action: &quot;new&quot; }
        format.json { render json: @rating.errors, status: :unprocessable_entity }
      end
    end
  end
  </code></pre>