Skip to content

Instantly share code, notes, and snippets.

@andreaseriksson
Created May 18, 2013 09:17
Show Gist options
  • Save andreaseriksson/5603829 to your computer and use it in GitHub Desktop.
Save andreaseriksson/5603829 to your computer and use it in GitHub Desktop.
RAILS Rest controller
class PagesController < ApplicationController
def index
@pages = Page.all
end
def show
@page = Page.find(params[:id])
end
def new
@page = Page.new
end
def edit
@page = Page.find(params[:id])
end
def create
@page = Page.new(params[:page])
if @page.save
redirect_to @page, notice: 'Page was successfully created.'
else
render action: "new"
end
end
def update
@page = Page.find(params[:id])
if @page.update_attributes(params[:page])
redirect_to @page, notice: 'Page was successfully updated.'
else
render action: "edit"
end
end
def destroy
@page = Page.find(params[:id])
@page.destroy
redirect_to pages_path, :notice => 'Page was successfully deleted.'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment