Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 4.0.3 role routing #2922

Closed
korun opened this issue Mar 7, 2014 · 2 comments
Closed

Rails 4.0.3 role routing #2922

korun opened this issue Mar 7, 2014 · 2 comments

Comments

@korun
Copy link

korun commented Mar 7, 2014

Hello.
I trying redirect users to a root path based on their roles, using this method and based on this docs.

authenticated :admin,    lambda { |u| u.has_role? :admin } do
  root :to => 'users#index', :as => :admin_root
end

authenticated :operator, lambda { |u| u.has_role? :operator } do
  root :to => 'tasks#index', :as => :operator_root
end

authenticated do # all other roles
  root :to => 'users#show', :as => :user_root
end

Then I go to root path, server always send me users#show.
Moreover, log says that has_role? method not called, it routes to users#show immediately.

Started GET "/" for 192.168.0.4 at 2014-03-07 16:08:18 +0400
  User Load (1.4ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
Processing by UsersController#show as HTML

What am I doing wrong? Or is it simply does not work in rails 4.0.3?

@lucasmazza
Copy link
Contributor

The first argument of authenticated is to match a specific scope, so authenticated :operator will only work for the Operator class and not User as you might be expecting (same thing goes for the :admin scope). I'm not sure, but maybe removing the symbol from the authenticated calls might provide the result you want.

I'm closing this since it does not seems to be a bug in Devise.

@korun
Copy link
Author

korun commented Mar 11, 2014

@lucasmazza, many thanks!
Removing symbol it not work for me, but if replace :operator and :admin to only :user it works perfectly!
Perhaps this method should be added to the documentation? I think I can do pull request, if needed.

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

No branches or pull requests

2 participants