Rails change default devise url - ruby-on-rails

I want to change the default rails url for user
current url => users/sign_in
new url => /user/sign_in
my current devise route is devise_for :users
how to get new url.
Please help me on this.

add this into routes.rb -
as :user do
get 'user/sing_in' => 'devise/sessions#new'
end

Related

Devise users/sign_in and users/show action trouble

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 !

How to remove sign_up path from devise retaining change password?

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

Devise & Custom Rails User URLs

I am currently using Rails 3.2.5 with the latest devise gem.
Currently users can access their profile page at...
example.com/users/john-doe
I want to remove the users portion of the url, so the url would be example.com/john-doe. Is this possible with devise?
Right now in my routes file I have the following...
devise_for :users, :controllers => {:omniauth_callbacks => 'omniauth_callbacks'}
Just add a route for it. You will probably want it to be the last one in the routes file.
Something like:
match '/:user' => "users#show", :as => :user_profile

Restrict access or redirect devise path users/sign_in

I am creating a rails app. And i have login in such a way that, users are directed or redirect to /login for signing in. And when users/sign_in is passed the it embeds the sign in form into the application layout which i don't want users to see. Is there a way i can redirect users/sign_in to /login or restrict access to it ?
thanks
The following will replace the routes:
devise_for :model_name, :path => '',
:path_names => {:sign_in => 'login', :sign_out => 'logout'}
It will replace the users/sign_in and users/sign_out routes with login/logout, and the redirects will take them to those routes accordingly as well.
try this. It should works. ;)
config/routes.rb
# change :devise_model to :user, or :admin or any name of your devise model
devise_scope :devise_model do
get '/login' => "devise/sessions#new"
end
and you can use this in view like this.
link_to 'Login', login_url
PS. if you have override devise controller. You should tell the router first, and change devise controller to your override controller name.
go to this link and see Configuring controllers content.

Configuring routes in devise when only using omniauth for authentication

I have built an application which allows a user to authenticate against Active Directory using omniauth-ldap. If this is a new user, the successful authentication creates a user for them based on information returned from AD. If the user already exists, it just logs them in. Users do not register for the application, they just log in with AD credentials. And I never want the user to log in with database credentials.
I can't figure out how to get rid of or change around some of the routes. For example if a user visits /sign_in they get the database authentication. And if the user visits sign_up they are taken to a page to register for the site. I would like for users that visit /sign_in to be taken to the LDAP login which is /users/auth/ldap. I think I need to make a custom route, but I'm not sure which controller I need to direct the user to. And I want to make the sign_up page go away entirely.
Right now I have a link that allows users to log in using ldap, and the path for that is user_omniauth_authorize_path(:ldap). I'm just not sure how to translate that into something that my config/routes.rb file understands. This is what I have in routes right now.
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
get 'sign_in', :to => 'devise/sessions#new', :as => :new_user_session
get 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session
end
When I run rake routes I do not see any route for user_omniauth_authorize_path which I presume is because that route is being generated by devise. So I think I need to have my routes point to a devise controller, but I can't seem to find the right path.
Try to add
:skip => [:sessions, :registrations] to your routes.rb
Something like this:
devise_for :users, :skip => [:sessions, :registrations]
This How To article might be helpful, and also here is one more link to go through.

Resources