Created
May 2, 2013 15:43
-
-
Save ch1ago/5503124 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 FoosController < ApplicationController | |
before_action :set_foo, only: [:show, :edit, :update, :destroy] | |
# GET /foos | |
def index | |
@foos = Foo.all | |
end | |
# GET /foos/1 | |
def show | |
end | |
# GET /foos/new | |
def new | |
@foo = Foo.new | |
end | |
# GET /foos/1/edit | |
def edit | |
end | |
# POST /foos | |
def create | |
@foo = Foo.new(foo_params) | |
if @foo.save | |
redirect_to @foo, notice: 'Foo was successfully created.' | |
else | |
render action: 'new' | |
end | |
end | |
# PATCH/PUT /foos/1 | |
def update | |
if @foo.update(foo_params) | |
redirect_to @foo, notice: 'Foo was successfully updated.' | |
else | |
render action: 'edit' | |
end | |
end | |
# DELETE /foos/1 | |
def destroy | |
@foo.destroy | |
redirect_to foos_url, notice: 'Foo was successfully destroyed.' | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_foo | |
@foo = Foo.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def foo_params | |
params.require(:foo).permit(:bar) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment