Skip to content

Instantly share code, notes, and snippets.

@rbarazi
Created March 19, 2010 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rbarazi/337147 to your computer and use it in GitHub Desktop.
Save rbarazi/337147 to your computer and use it in GitHub Desktop.
[Beginning Rails 3] Listing 7-2. Updated app/controllers/users_controller.rb
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
redirect_to articles_path, :notice => 'User successfully added.'
else
render :action => 'new'
end
end
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
redirect_to articles_path, :notice => 'Updated user information successfully.'
else
render :action => 'edit'
end
end
end
@angus65
Copy link

angus65 commented Oct 9, 2010

Should the 'redirect_to' be pointing to 'users_path' or is 'articles_path' correct' ?

@rbarazi
Copy link
Author

rbarazi commented Oct 11, 2010

"redirect_to articles_path" is correct. As you can see in this controller (UserController) there is no 'index' action to list all users. We used "articles_path" to redirect to after an update or a creation of a user happen.

@angus65
Copy link

angus65 commented Nov 17, 2010

Thank you. Still learning... Very different from C# winforms but I really like what I see.

@aruprakshit
Copy link

In Book you said, Updated app/controllers/users_controller.rb: http://gist.github.com/337147 .. But this gist is not updated as per the code in the book. Book's code is correct only. Here is the correct gist which this gist supposed to contain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment