title: Rails - getting the value out from the view form into a controller
body: <p>In my form the user has to select a category for his post. </p>
  
  <pre><code>  &lt;div class="field form-group"&gt;
      &lt;%= f.text_field :category, class: "form-control" %&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>(Currently I am using text-input instead of a drop-down list)</p>
  
  <p>Posts belong to categories</p>
  
  <pre><code>@post = @category.posts.build(post_params)
  </code></pre>
  
  <p>However I can't understand how to get the category value out of that field.
  I have tried passing a number, to find_by id, and string to find_by name. </p>
  
  <pre><code>@category = Category.find(params[:category]) #returns no Categoy with nil id
  @category = Category.find_by(name: params[:category]) #returns no method error
  </code></pre>
  
  <p>any help would be appreciated</p>
  
  <p>Edit:</p>
  
  <p>Form code</p>
  
  <pre><code>&lt;%= form_for [@company, @post], :html =&gt; { :class =&gt; "form-posts"} do |f| %&gt;
  
    &lt;div class="field form-group"&gt;
      &lt;div class="input-group input-group-lg"&gt;
        &lt;span class="input-group-addon"&gt;$&lt;/span&gt;
        &lt;%= f.text_field :text, class: "form-control", placeholder: "text", required: true %&gt;
        &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;div class="field form-group"&gt;
                  &lt;div class="input-group"&gt;
                      &lt;span class="input-group-addon"&gt;
                          &lt;i class="glyphicon glyphicon-calendar"&gt;&lt;/i&gt;
                      &lt;/span&gt;
                      &lt;%= f.text_field :date, 
                                        class: "form-control", 
                                        value: @today, 
                                        data: {behaviour: "datepicker"},
                                        required: true %&gt;
                  &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;div class="field form-group"&gt;
      &lt;%= f.text_field :comment, class: "form-control", placeholder: "Comment (optional)" %&gt;
    &lt;/div&gt;
  
    &lt;div class="field form-group"&gt;
      &lt;%= f.text_field :category, class: "form-control" %&gt;
    &lt;/div&gt;
  
    &lt;div class="actions"&gt;&lt;%= f.submit 'Add', class: "btn btn-lg btn-primary" %&gt;&lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Edit 2</p>
  
  <p>controller:</p>
  
  <p>form:</p>
  
  <pre><code>&lt;%= f.text_field :category, class: "form-control" %&gt;
  </code></pre>
  
  <p>def create</p>
  
  <pre><code>@company = current_user.companies.find(params[:company_id])
  @category = @company.categories(params[:category])
  @post = @category.posts.build(post_params)
  </code></pre>
  
  <p>debugger:</p>
  
  <pre><code>{"utf8"=&gt;"✓", "authenticity_token"=&gt;"...", "transaction"=&gt;{"text"=&gt;"lalala", "date"=&gt;"11.11.2013", "comment"=&gt;"", "category"=&gt;"5"}, "commit"=&gt;"Add post", "action"=&gt;"create", "controller"=&gt;"posts", "company_id"=&gt;"2"}
  
  undefined method `transactions'
  </code></pre>