Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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