Advertisement
Ankhwatcher

users_controller.rb

Aug 12th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.13 KB | None | 0 0
  1. class UsersController < ApplicationController
  2.   before_action :set_user, only: [:show, :edit, :update, :destroy]
  3.  
  4.   # GET /users
  5.   def index
  6.     @users = User.all
  7.   end
  8.  
  9.   # GET /users/1
  10.   def show
  11.   end
  12.  
  13.   # GET /users/new
  14.   def new
  15.     @user = User.new
  16.   end
  17.  
  18.   # GET /users/1/edit
  19.   def edit
  20.   end
  21.  
  22.   # POST /users
  23.   def create
  24.     @user = User.new(user_params)
  25.  
  26.     if @user.save
  27.       redirect_to @user, notice: 'User was successfully created.'
  28.     else
  29.       render action: 'new'
  30.     end
  31.   end
  32.  
  33.   # PATCH/PUT /users/1
  34.   def update
  35.     if @user.update(user_params)
  36.       redirect_to @user, notice: 'User was successfully updated.'
  37.     else
  38.       render action: 'edit'
  39.     end
  40.   end
  41.  
  42.   # DELETE /users/1
  43.   def destroy
  44.     @user.destroy
  45.     redirect_to users_url, notice: 'User was successfully destroyed.'
  46.   end
  47.  
  48.   private
  49.     # Use callbacks to share common setup or constraints between actions.
  50.     def set_user
  51.       @user = User.find(params[:id])
  52.     end
  53.  
  54.     # Only allow a trusted parameter "white list" through.
  55.     def user_params
  56.       params.require(:user).permit(:username)
  57.     end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement