Skip to content

Instantly share code, notes, and snippets.

@laurenhavertz
Last active December 21, 2015 01:19
Show Gist options
  • Save laurenhavertz/6226935 to your computer and use it in GitHub Desktop.
Save laurenhavertz/6226935 to your computer and use it in GitHub Desktop.
DOCUMENTATION

CONTROLLER ACTIONS

ITEMS CONTROLLER

  1. Create a User Controller rails g controller users in the terminal
  • Consider what you want your controller methods to do!
  1. Create a 'show' method def show @user = User.find(params[:id]) end
  2. Create a 'new' method def new @user = User.new end
  3. Create a 'create' method def create @user = User.new(params[:user]) if @user.save render: show else flash[:error] = @user.errors.full_messages render: new end
  4. Create an 'edit' method def edit @user = User.find(params[:id]) end
  5. Create an 'update' method def update @user.find(params[:id]) @user.update_attributes(params[:user]) render :show end
  6. Create a 'destroy' method def destroy user = User.find(params[:id]) user.delete redirect_to(users_path) end

LIST CONTROLLER

  1. Create a User Controller rails g controller lists in the terminal
  • Consider what you want your controller methods to do!
  1. Create a 'show' method def show @list = List.find(params[:id]) end
  2. Create a 'new' method def new @list = List.new end
  3. Create a 'create' method def create @list = User.new(params[:list]) if @list.save render: show else flash[:error] = @list.errors.full_messages render: new end
  4. Create an 'edit' method def edit @list = list.find(params[:id]) end
  5. Create an 'update' method def update @list.find(params[:id]) @list.update_attributes(params[:list]) render :show end
  6. Create a 'destroy' method def destroy list = List.find(params[:id]) list.delete redirect_to(users_path) end
  7. Create an 'index' method def index @list = List.all end

ITEM CONTROLLER

  1. Create an Item Controller rails g controller items in the terminal
  • Consider what you want your controller methods to do!
  1. Create a 'show' method def show @item = Item.find(params[:id]) end
  2. Create a 'new' method def new @item = Item.new end
  3. Create a 'create' method def create @item = Item.new(params[:item]) if @item.save render: show else flash[:error] = @item.errors.full_messages render: new end
  4. Create an 'edit' method def edit @item = Item.find(params[:id]) end
  5. Create an 'update' method def update @item.find(params[:id]) @item.update_attributes(params[:item]) render :show end
  6. Create a 'destroy' method def destroy item = Item.find(params[:id]) item.delete redirect_to(item_path) end

ROUTES

  • in config/routes.rb resources :users, :lists, :items `root to :'list#index'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment