title: How do I filter posts with Ruby-on-Rails
body: <p>I have a job listing project set up and I want to be able to filter by several filters. I want to be able to have sidebar which can filter by certain elements - :city, :jobtype, and :contracttype</p>
  
  <p>Is there a straightforward way to create radio buttons that will display the options available to the user i.e for :city a list of London, Manchester, Brighton etc which can be ticked to display those specific jobs?</p>
  
  <p>I'm new to rails so having a hard time working out what I need to do, if anyone could explain what I need to do I'd really appreciate it!</p>
  
  <p>My code is as follows: </p>
  
  <p>index.html.erb -</p>
  
  <pre><code>&lt;% @jobs.each do |job| %&gt;
  &lt;div class="job"&gt;
      &lt;h2&gt;&lt;%= job.position %&gt;&lt;/h2&gt;
      &lt;p&gt;Company: &lt;%= job.company %&gt;&lt;/p&gt;
      &lt;p&gt;Salary: &lt;%= job.salary %&gt;&lt;/p&gt;
      &lt;p&gt;&lt;a href="http://&lt;%= job.companywebsite %&gt;" target="_blank"&gt;Website: &lt;%= job.companywebsite %&gt;&lt;/a&gt;&lt;/p&gt;
      &lt;p&gt;&lt;a href="http://www.twitter.com/&lt;%= job.companytwitter %&gt;" target="_blank"&gt;Twitter: &lt;%= job.companytwitter %&gt;&lt;/a&gt;&lt;/p&gt;
      &lt;p&gt;Contract Type: &lt;%= job.contract %&gt;&lt;/p&gt;
      &lt;p&gt;City: &lt;%= job.city %&gt;&lt;/p&gt;
      &lt;p&gt;Expiry date: &lt;%= job.expirydate %&gt;&lt;/p&gt;
      &lt;p&gt;Job Type: &lt;%= job.jobtype %&gt;&lt;/p&gt;
      &lt;p&gt;Full Description:&lt;br&gt;&lt;br&gt;&lt;%= job.description %&gt;&lt;/p&gt;
      &lt;p&gt;How to apply: &lt;%= job.apply %&gt;&lt;/p&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>job.rb - </p>
  
  <pre><code>class Job &lt; ActiveRecord::Base
     validates :position, presence: true
     validates :company, presence: true
     validates :salary, presence: true
     validates :companywebsite, presence: true
     validates :companytwitter, presence: true
     validates :contract, presence: true
     validates :city, presence: true
     validates :expirydate, presence: true
     validates :jobtype, presence: true
     validates :description, presence: true
     validates :apply, presence: true
  end
  </code></pre>
  
  <p>jobs_controller.erb - </p>
  
  <pre><code>class JobsController &lt; ApplicationController
    def index
      @jobs = Job.page(params[:page]).per(25)
    end
  
    def new
      @job = Job.new
    end
  
    def create
      @job = Job.new(params.require(:job).permit(:position, :company, :salary, :companywebsite, :companytwitter, :contract, :city, :expirydate, :jobtype, :description, :apply ))
      if @job.save
        redirect_to root_path
      else
        render "new"
      end
    end
  end
  </code></pre>
  
  <p>new.html.erb - </p>
  
  <pre><code>&lt;%= simple_form_for @job, html: { multipart: true } do |form| %&gt;
  &lt;%= form.input :position, input_html: { maxlength: 60 }, placeholder: "Job Position", label: false %&gt;
  &lt;%= form.input :company, input_html: { maxlength: 60 }, placeholder: "Company name", label: false %&gt;
  &lt;%= form.input :salary, input_html: { maxlength: 60 }, placeholder: "Salary", label: false %&gt;
  &lt;%= form.input :companywebsite, input_html: { maxlength: 60 }, placeholder: "Company Website", label: false %&gt;
  &lt;%= form.input :companytwitter, input_html: { maxlength: 60 }, placeholder: "Twitter Handle e.g @Hatch_Inc", label: false %&gt;
  &lt;%= form.input :contract, input_html: { maxlength: 60 }, placeholder: "Contract Type", label: false %&gt;
  &lt;%= form.input :city, input_html: { maxlength: 60 }, placeholder: "City", label: false %&gt;
  &lt;%= form.input :expirydate, input_html: { maxlength: 60 }, placeholder: "Expiry date", label: false %&gt;
  &lt;%= form.input :jobtype, input_html: { maxlength: 60 }, placeholder: "Job Type", label: false %&gt;
  &lt;%= form.input :description, input_html: { maxlength: 60 }, placeholder: "Full job description", label: false %&gt;
  &lt;%= form.input :apply, input_html: { maxlength: 60 }, placeholder: "How to apply", label: false %&gt;
  &lt;%= form.button :submit %&gt;
  &lt;% end %&gt;
  </code></pre>