Skip to content

Instantly share code, notes, and snippets.

@yoonwaiyan
Created May 21, 2015 13:14
Show Gist options
  • Save yoonwaiyan/358c3489a933229b2ea2 to your computer and use it in GitHub Desktop.
Save yoonwaiyan/358c3489a933229b2ea2 to your computer and use it in GitHub Desktop.
Controller Scaffold
class BookController < ApplicationController
def list
@books = Book.find(:all)
end
def show
@book = Book.find(params[:id])
end
def new
@book = Book.new
@subjects = Subject.find(:all)
end
def create
@book = Book.new(params[:book])
if @book.save
redirect_to :action => 'list'
else
@subjects = Subject.find(:all)
render :action => 'new'
end
end
def edit
@book = Book.find(params[:id])
@subjects = Subject.find(:all)
end
def update
@book = Book.find(params[:id])
if @book.update_attributes(params[:book])
redirect_to :action => 'show', :id => @book
else
@subjects = Subject.find(:all)
render :action => 'edit'
end
end
def delete
Book.find(params[:id]).destroy
redirect_to :action => 'list'
end
def show_subjects
@subject = Subject.find(params[:id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment