Skip to content

Instantly share code, notes, and snippets.

@aruprakshit
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aruprakshit/2affc79abb919ab5acab to your computer and use it in GitHub Desktop.
Save aruprakshit/2affc79abb919ab5acab to your computer and use it in GitHub Desktop.
In correction of the Gist - https://gist.github.com/rbarazi/337147
# This gist is the correct one taken from Book Beginning Rails 4. The gist they mentioned in the book accidentally contains wrong
# code. Thus I created this gist, so that you can copy the code directly and move on.
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
redirect_to articles_path, notice: 'User successfully added.'
else
render action: :new
end
end
def edit
end
def update
if @user.update(user_params)
redirect_to articles_path, notice: 'Updated user information successfully.'
else
render action: 'edit'
end
end
private
def set_user
@user = User.find(params[:id])
end
def user_params
params
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment