I want to remove the default sign up path or just route the sign_up path to sign_in. Is it possible to do so? I want to retain the change password option. so removing registerable on model is not a good idea. Thanks.
You can use devise_scope for the same. In your routes.rb file define a scope like following before devise_for.
devise_scope :user do
get "users/sign_up", :to => "devise/sessions#new", :as => :sign_up
end
Related
I user devise 3.4.0 under rails 4.1.0.
I want to add user detail page, so I made this route
get 'users/:id' => 'users#show', as: 'user'
But after this, when I access /users/sign_in path, it try to find the user show page.
How to write the right route?
What you did will actually "override" the devise routes (and i think this is the problem you are facing)
If you want to add another route in the scope of devise routes, you have to do something like :
devise_scope :user do
get '/users/:id' => 'users#show'
end
after
devise_for :users
Let me know if it solves the problem !
I got three independent devise models, ergo I got three different sign_in screen. And all three have got a dashboard:
devise_for :md1
devise_for :md2
devise_for :md3
match 'md1/dashboard' => 'md1#dashboard', :via => :get
match 'md2/dashboard' => 'md2#dashboard', :via => :get
match 'md3/dashboard' => 'md3#dashboard', :via => :get
I want when there is a mdX succesfully sign in, it will redirect to mdX#dashboard, and if it is possible by GET. I tried:
devise_scope :md1 do
root :to => 'md1#dashboard'
end
devise_scope :md2 do
root :to => 'md2#dashboard'
end
devise_scope :md3 do
root :to => 'md3#dashboard'
end
Then when I succesfully sign in with md1 I got redirected to md1 dashboard, but when I succesfully sign in with md2 I got redirected to md1's sign_in screen.
Then I tried:
def after_sign_in_path_for resource
dashboard_path resource
end
But there isn't such method. Is there an easy way to do this or it has to be with the if statements for each model?
UPDATE
Some routes to make a better understanding and more information to get a better solution
md1_dashboard GET /md1/dashboard(.:format) md1#dashboard
md2_dashboard GET /md2/dashboard(.:format) md2#dashboard
md3_dashboard GET /md3/dashboard(.:format) md3#dashboard
Thanks in advance
When you are writing this:
devise_scope :md1 do
root :to => 'md1#dashboard'
end
devise_scope :md2 do
root :to => 'md2#dashboard'
end
devise_scope :md3 do
root :to => 'md3#dashboard'
end
You are defining three root routes, with the same name. Since they conflict, only the first will be used. That's why only md1 worked. You probably meant to write this:
scope :md1 do
root :to => 'md1#dashboard'
end
scope :md2 do
root :to => 'md2#dashboard'
end
scope :md3 do
root :to => 'md3#dashboard'
end
On this case, you will define three different root routes, at three different scopes (check rake routes again). Note scope is a router method that scopes your routes, devise_scope does not scope any route, it simply tells which devise scope you want to use, which you don't need to tell unless Devise explicitly asks you so (you will know when it does).
After this change, everything should work as expected. Note that Devise by default uses #{scope}_root_path to redirect after successful sign in, that's why the code above works (check rake routes and you will see you md1_root, md2_root, etc are now defined).
I want, instead of /user/:id I want the default user route to be /user:created_at I was able to get /user:id to work (without the second /) however when I try to do :created_at I get an error.
Does anyone know how to fix this? Also, even though I have match 'users:id', :to => 'users#show', :as => :user, :via => :get /user/1 still is a valid link since I have resources :users in my config/routes.rb. Is there a way to remove the default /user/:id when rails compiles the resources :users?
If I understand it correctly you can either use to_param: http://apidock.com/rails/ActiveRecord/Base/to_param
so if you used in your user model
def to_param
"#{first_name}_#{last_name}"
end
then user_path(#user) would generate /users/planet_pluto for example
to prevent a route to be generated by map.resources simply use :except
map.resources :user, :except => [:show]
hope that helps
Goal
When user submits the devise "edit registration" form, I want to redirect to users#show rather than the site's root.
Problem
Following Devise's instructions has not worked. I don't want to customize the Devise controller, so I'm left with two suggested modifications to routes.rb, either
devise_for :users do
get 'users', :to => 'users#show', :as => :user_root
end
or
match 'user_root' => 'users#show'
The first redirects to http://localhost:3000/users after submitting the edit form, the second redirects to http://localhost:3000/user_root. Both give the same error, "Couldn't find User without an ID".
My users#show page normally works in the app, so it's not an error with the controller method (or view, of course). It seems to be a routing error. I have "resources :users" in my routes.rb file, nothing else regarding users. If I need to give more information please let me know!
Question
Why isn't the user id being passed in the url?
Have you considered making the action a member action? this will ensure that the url format is controller//action. I don't know if you can even use the member thing in the devise route definition, but that's where I'd start.
devise_for :users do
member do
get 'users', :to => 'users#show', :as => :user_root
end
end
The member part doesn't work but if you take that out it is working for me. +1 to jaydel for close enough :P
devise_for :users do
get 'users', :to => 'users#show', :as => :user_root
end
Another thing that I tried which also worked was :
devise_scope :user do
get 'users' => 'users#show', :as => :user_root
end
I use devise for authentication. I have an admin user to play with the application. Is it possible to map the urls '/login' and '/admin' to the same login form?
Yes you can. Add the following to your routes.rb file, assuming your devise model is called 'admin':
devise_scope :admin do
get 'login' => 'devise/sessions#new'
get 'admin' => 'devise/sessions#new'
end
The normal '/admins/sign_in' route will still be available as well.