Created
May 18, 2013 09:17
-
-
Save andreaseriksson/5603829 to your computer and use it in GitHub Desktop.
RAILS Rest controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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