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
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?
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!
My code is as follows:
index.html.erb -
<% @jobs.each do |job| %>
<div class="job">
<h2><%= job.position %></h2>
<p>Company: <%= job.company %></p>
<p>Salary: <%= job.salary %></p>
<p><a href="http://<%= job.companywebsite %>" target="_blank">Website: <%= job.companywebsite %></a></p>
<p><a href="http://www.twitter.com/<%= job.companytwitter %>" target="_blank">Twitter: <%= job.companytwitter %></a></p>
<p>Contract Type: <%= job.contract %></p>
<p>City: <%= job.city %></p>
<p>Expiry date: <%= job.expirydate %></p>
<p>Job Type: <%= job.jobtype %></p>
<p>Full Description:<br><br><%= job.description %></p>
<p>How to apply: <%= job.apply %></p>
</div>
<% end %>
job.rb -
class Job < 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
jobs_controller.erb -
class JobsController < 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
new.html.erb -
<%= simple_form_for @job, html: { multipart: true } do |form| %>
<%= form.input :position, input_html: { maxlength: 60 }, placeholder: "Job Position", label: false %>
<%= form.input :company, input_html: { maxlength: 60 }, placeholder: "Company name", label: false %>
<%= form.input :salary, input_html: { maxlength: 60 }, placeholder: "Salary", label: false %>
<%= form.input :companywebsite, input_html: { maxlength: 60 }, placeholder: "Company Website", label: false %>
<%= form.input :companytwitter, input_html: { maxlength: 60 }, placeholder: "Twitter Handle e.g @Hatch_Inc", label: false %>
<%= form.input :contract, input_html: { maxlength: 60 }, placeholder: "Contract Type", label: false %>
<%= form.input :city, input_html: { maxlength: 60 }, placeholder: "City", label: false %>
<%= form.input :expirydate, input_html: { maxlength: 60 }, placeholder: "Expiry date", label: false %>
<%= form.input :jobtype, input_html: { maxlength: 60 }, placeholder: "Job Type", label: false %>
<%= form.input :description, input_html: { maxlength: 60 }, placeholder: "Full job description", label: false %>
<%= form.input :apply, input_html: { maxlength: 60 }, placeholder: "How to apply", label: false %>
<%= form.button :submit %>
<% end %>