Last active
August 29, 2015 14:03
-
-
Save aruprakshit/2affc79abb919ab5acab to your computer and use it in GitHub Desktop.
In correction of the Gist - https://gist.github.com/rbarazi/337147
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
# 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