rubyonrailsin

A Ruby and Rails talk

Sunday, March 21, 2010


[Rails] Error in the code Doube Render (colins')

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

Hi everyone, i followed colins example and it worked perfectly but now i
get this error

ActionController::DoubleRenderError in UserController#login

Render and/or redirect were called multiple times in this action. Please
note that you may only call render OR redirect, and at most once per
action. Also note that neither redirect nor render terminate execution
of the action, so if you want to exit an action after redirecting, you
need to do something like "redirect_to(...) and return".

I feel that something is wrong with this code

def login
@title = "Login - Books"

if request.post?
@user = User.new(params[:user])
user = User.find_by_screen_name_and_password(@user.screen_name,
@user.password)
if user
session[:user_id] = user.id
flash[:notice] = "User #{user.screen_name} logged in"
redirect_to :action => "index"
else
# Don't show the password in the view
@user.password = nil
flash[:notice] = "Invalid email/password combination"
end
end

if session[:user_id]
flash[:notice] = "Already registed and logged in! You cannot view
the register or login!"
redirect_to :action => :index
end
end

///////////////////////////////////////////////////////

if session[:user_id]
flash[:notice] = "Already registed and logged in! You cannot view
the register or login!"
redirect_to :action => :index
end

///////////////////////////////////////////////////////

what this does, is if session ID is found, then it takes the login page
back to index...can someone help me please :(
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive