I'm trying to modify an existing devise route to hold parameters
Here is the working route:
devise_for :contributors, controllers: {registrations: 'contributors/registrations', confirmations: 'contributors/confirmations'}
the working path:
<p>Create Account</p>
I need to be able to pass a parameter with it. Is there a simple way to do this?
I was thinking of doing something like this:
devise_for :contributors, controllers: {registrations: 'contributors/registrations(/:contributor_type)', confirmations: 'contributors/confirmations'}
<p>Create Account</p>
but no luck, it only returns this error: wrong constant name Registrations(
Nevermind, I didn't need to place a parameter inside the devise_for route declaration.
devise_for :contributors, controllers: {registrations: 'contributors/registrations', confirmations: 'contributors/confirmations'}
this works just fine with
<p>Create Account</p>
Related
Here's my issue, I want to correctly nest my devise routes from :
user_je_session POST /users/jes/:je_id/sign_in(.:format)
to :
user_je_session POST /jes/:je_id/users/sign_in(.:format)
The objective is that my users can have multiple accounts, depending on the "je" they want to access.
there's my actual routes :
root to: 'pages#home'
devise_for :admins, controllers: { sessions: 'admin/sessions', registrations: 'admin/registrations' }
resources :jes, param: :nom do
devise_for :users, controllers: { sessions: 'users/sessions', registrations: 'users/registrations' }
end
Thanks for your help
I think it's easier to use devise_scope. You can customize the devise routes as you wish. Something like this might be work:
devise_for :admins, controllers: {
sessions: 'admin/sessions',
registrations: 'admin/registrations'
}
as :admin do
# Please change to: value to your actual controller or action
post '/jes/:je_id/users/sign_in', to: 'admin/sessions#create'
end
Please read more on the documentation page.
https://github.com/heartcombo/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes
I'm having issues with routing with Devise and my Users model. I was trying to get sign_out to work and found an answer that suggested this.
// routes.rb
devise_for :users do
get '/users/sign_out' => 'devise/sessions#destroy'
get '/users/sign_in' => 'devise/sessions#create'
end
And while this works for signing out, if I use just that I cannot view a User.
No route matches [GET] "/users/1"
However, if I add back resources :users, I run into the first issue where sign_out or sign_in try to view a User.
Couldn't find User with 'id'=sign_out
How do I add /users/index to the devise_for loop?
Thanks for your help.
Try adding resources :users after your devise_for block.
You can also use the following:
devise_for :users, path: '', path_names: { sign_in: 'login', sign_out: 'logout'}
I'm using OAuth 2 gem to authenticate via google and facebook.
I need to do logout from google and facebook when I logout from my application. In OA documentation said to:
devise_scope :user do
delete 'sign_out', to: 'devise/sessions#destroy', as: :destroy_user_session
end
Add this to routes.rb. I did it so, my routs rb now looks like:
Rails.application.routes.draw do
devise_for :users, controllers: { omniauth_callbacks: 'callbacks' }
devise_scope :user do
delete 'sign_out', to: 'devise/sessions#destroy', as: :destroy_user_session
end
When I add this line, i got an error when i try to rails s my application:
/Users/damirik/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:507:in add_route': Invalid route name, already in use: 'destroy_user_session' (ArgumentError)
You may have defined two routes with the same name using the:as` option, or you may be overriding a route already defined by a resource with the same naming.
I really dont understand how to fix it. Help please
Looking at the devise_for method documentation, I can see that it already adds the exact delete 'sign_out' route, which makes it redundant.
This should be enough to make your code work.
Rails.application.routes.draw do
devise_for :users, controllers: { omniauth_callbacks: 'callbacks' }
end
I am following this guide https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
to configure devise with omniauth facebook sign up, now I am at the step where I need to add the omniauth_callbacks route to the devise routes, i have already customized a devise controller like this :
devise_for :users, controllers:{
registrations: "users/registrations"
}
So I added the omniauth route like this
devise_for :users, controllers:{
registrations: "users/registrations"
:omniauth_callbacks => "users/omniauth_callbacks"
}
But now the server is not starting because of a syntax error, I am pretty sure I need a block in the routes.
Please advise.
Thanks
You just have a missing comma
devise_for :users, controllers: {
registrations: "users/registrations",
omniauth_callbacks: "users/omniauth_callbacks"
}
I am using Devise for authentication and I want to have URLs of the form /user/:id but I am not sure how to do this.
I guess I need to edit the routes file but not sure what change to make? Is there a simple way to do this?
My routes.rb file looks like this:
devise_for :users, :controllers => {:registrations => 'registrations'}
Thanks