Thursday, 15 July 2010

Rails calls unexpected controller action instead of redirecting -



Rails calls unexpected controller action instead of redirecting -

i have believe bizarre bug in rails app.

what app allows sign up. after sign sends activation email link activate account. link looks this:

http://localhost:3000/users/24932b7edf2e7cc7c9e8e51b8e7a7f75a88016f9/activate

and route looks this:

activate /users/:activation_code/activate(.:format) users#activate

you click link, , calls activate method in users controller, looks this:

def activate @user = user.find_by_activation_code(params[:activation_code]) if @user.nil? flash[:error] = "user not found or activated. seek logging in" else @user.activate flash[:success] = "user activated" end redirect_to login_path end

this gets fuzzy. instead of redirecting login_path, app tries phone call different action in users controller, , rails app chokes. cannot life of me understand happening. tries redirect location action in users controller instead of login_path, , fails error couldn't find user without id. location action looks this:

def location @user = user.find(params[:id]) end

and naturally fails because in case there no :id parameter in url. here's relevant part of stack trace. line 130 phone call redirect, calls location action.

app/controllers/users_controller.rb:38:in `location' app/controllers/users_controller.rb:130:in `activate'

if remove or comment redirect_to login_path, doesn't seek phone call location method in users controller, , falls on view activate action, doesn't exist. here routes:

location_user /users/:id/location(.:format) users#location login /login(.:format) sessions#new

does have ideas?

edit: pasting log entries

processing userscontroller#activate html parameters: {"activation_code"=>"24932b7edf2e7cc7c9e8e51b8e7a7f75a88016f9"} user load (0.5ms) select `users`.* `users` `users`.`id` = 1 limit 1 cache (0.0ms) select `users`.* `users` `users`.`id` = 1 limit 1 user load (0.7ms) select `users`.* `users` `users`.`activation_code` = '24932b7edf2e7cc7c9e8e51b8e7a7f75a88016f9' limit 1 redirected completed 404 not found in 29.4ms activerecord::recordnotfound (couldn't find user without id): app/controllers/users_controller.rb:38:in `location' app/controllers/users_controller.rb:130:in `activate'

well, seems have been issue name of action :location

when changed def location def map, works fine now.

i hope helps @ point!

ruby-on-rails

No comments:

Post a Comment