I need to send on my Devise registration form params of the actual language that the user selected and that I keep in the route as params[:lang].
I have a custom controller because I am validating a reCaptcha(that part works).
So I have in my routes:
devise_for :users, controllers: { registrations: 'registrations' }
devise_for :users do
root :to => "devise/registrations#new"
get "/" => "devise/registrations#new"
post '/' => 'registrations#new', :as => :new_user_registration
match '/', :to => 'devise/registrations#new'
get "/logout", :to => "devise/sessions#destroy", :as => "logout"
end
#Sign
match '/:lang/:sec/sign' => 'frontend#sign', :as => :sign
In my register form:
<%= form_for(resource, :as => resource_name, :url =>
registration_path(resource_name, :lang => params[:lang], :sec => params[:sec]))
do |f| %>
And i have two controllers, one for users and another for administrators, on successful login, Devise goes to the users controller, callers Restringido and wonders whether the user is validates as admin or only a common user.
In my restringido controller:
class RestringidoController < ApplicationController
before_filter :verify_is_user
def verify_is_user
if current_user.try(:admin?)
#redireccionar a backend
redirect_to :controller => "backend", :action => "index"
elsif current_user
#mantenerte en este controlador
else
redirect_to :controller => "frontend", :action => "sign"
end
And my backend controller for administrators:
before_filter :verify_is_admin
def verify_is_admin
if current_user.admin?
else
redirect_to root_path
end
And the error is:
No route matches {:controller=>"frontend", :action=>"sign"}
Your route:
match '/:lang/:sec/sign' => 'frontend#sign', :as => :sign
requires the :lang
variable to be set, and you have not provided a default value. So this call in the controller:
redirect_to :controller => "frontend", :action => "sign"
will fail to match the route, because you have not provided a :lang
variable
To fix this, you can either provide the :lang
value in the controller eg:
redirect_to :controller => "frontend", :action => "sign", :lang => (params[:lang] || DEFAULT_LANG)
or have a default value in the route.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.