### JOB - new.html.erb

<% form_for(@job) do |f| %>
<%= f.error_messages %>

<p>
<% Category.all.each do |category| %>
<label><%= f.radio_button :category_id, category.id %> <%=h category.name.titleize %></label>
<% end -%>
</p>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', jobs_path %>


#### JOB - job.rb (model file)
class Job < ActiveRecord::Base
belongs_to :category
end


#### JOB - category.rb (model file)
class Category < ActiveRecord::Base
has_many :jobs
end


#### JOB - jobs_controller.rb (controller file)
class JobsController < ApplicationController
def index
@category = Category.new
@jobs = Job.all

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @jobs }
end
end

def show
@job = Job.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @job }
end
end

def new
@job = Job.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @job }
end
end

def edit
@job = Job.find(params[:id])
end

def create
@job = Job.new(params[:job])

respond_to do |format|
if @job.save
format.html { redirect_to(@job, :notice => 'Job was successfully created.') }
format.xml { render :xml => @job, :status => :created, :location => @job }
else
format.html { render :action => "new" }
format.xml { render :xml => @job.errors, :status => :unprocessable_entity }
end
end
end

def update
@job = Job.find(params[:id])

respond_to do |format|
if @job.update_attributes(params[:job])
format.html { redirect_to(@job, :notice => 'Job was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @job.errors, :status => :unprocessable_entity }
end
end
end

def destroy
@job = Job.find(params[:id])
@job.destroy

respond_to do |format|
format.html { redirect_to(jobs_url) }
format.xml { head :ok }
end
end
end