Skip to content

Instantly share code, notes, and snippets.

@Tasemu
Created December 5, 2013 09:01
Show Gist options
  • Save Tasemu/7802266 to your computer and use it in GitHub Desktop.
Save Tasemu/7802266 to your computer and use it in GitHub Desktop.
<h1>Listing jobs</h1>
<table>
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Tea</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @jobs.each do |job| %>
<tr>
<td><%= job.title %></td>
<td><%= job.description %></td>
<td><%= job.tea %></td>
<td><%= link_to 'Show', job %></td>
<td><%= link_to 'Edit', edit_job_path(job) %></td>
<td><%= link_to 'Destroy', job, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Job', new_job_path %>
class JobsController < ApplicationController
before_action :set_job, only: [:show, :edit, :update, :destroy]
# GET /jobs
# GET /jobs.json
def index
@jobs = Job.all
respond_to do |format|
format.html
format.json { render json: @jobs }
end
end
# GET /jobs/1
# GET /jobs/1.json
def show
respond_to do |format|
format.html
format.json { render json: @job }
end
end
# GET /jobs/new
def new
@job = Job.new
end
# GET /jobs/1/edit
def edit
end
# POST /jobs
# POST /jobs.json
def create
@job = Job.new(job_params)
respond_to do |format|
if @job.save
format.html { redirect_to '/', notice: 'Job was successfully created.' }
format.json { render action: 'show', status: :created, location: @job }
else
format.html { render action: 'new' }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /jobs/1
# PATCH/PUT /jobs/1.json
def update
respond_to do |format|
if @job.update(job_params)
format.html { redirect_to @job, notice: 'Job was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
end
end
# DELETE /jobs/1
# DELETE /jobs/1.json
def destroy
@job.destroy
respond_to do |format|
format.html { redirect_to jobs_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_job
@job = Job.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def job_params
params.require(:job).permit(:title, :description, :tea, :image)
end
end
Railsportfolio::Application.routes.draw do
root "home#index"
resources :jobs
scope :api do
get '/jobs(.:format)' => 'jobs#index'
get '/jobs/:id(.:format)' => 'jobs#show'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment