Я работаю над новым приложением и пытаюсь настроить, куда Devise отправляет зарегистрированного или нового зарегистрированного пользователя после отправки формы входа.
Я хочу отправить пользователя обратно на страницу, с которой было вызвано действие входа, поэтому я создал эти методы в application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
def store_location
session[:origin_url] = request.request_uri if request.get? and controller_name != "user_sessions" and controller_name != "sessions"
end
def redirect_back_or_default(default)
redirect_to(session[:origin_url] || default)
end
def after_sign_in_path_for(resource_or_scope)
[#https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in][1]
p "*********** About to check session"
if session[:origin_url]
p "*****************Redirecting after sign_in to " + session[:origin_url]
redirect_back_or_default(docs_path)
return #this syntax needs to be checked
else
super
end
return
end
end
Вот docs_controller, код действия шоу:
# GET /docs/1
# GET /docs/1.xml
def show
@doc = Doc.find(params[:id])
store_location
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @doc }
end
end
А вот вывод из журнала сервера:
"*********** About to check session"
"*****************Redirecting after sign_in to /docs/3"
Started GET "/users/sign_in" for 127.0.0.1 at Wed Mar 02 01:12:16 +0100 2011
Processing by Devise::SessionsController#new as HTML
User Load (0.9ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1
Redirected to http://localhost:3000/docs/3
Redirected to
Completed in 119ms
ActionController::ActionControllerError (Cannot redirect to nil!):
Rendered /home/jon/.rvm/gems/ruby-1.8.7-p334@rails3/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.7ms)
Rendered /home/jon/.rvm/gems/ruby-1.8.7-p334@rails3/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (955.7ms)
Rendered /home/jon/.rvm/gems/ruby-1.8.7-p334@rails3/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (986.3ms)
Я использую Rails 3.0.5
Спасибо за любой совет ...