customizing the devise gem controller in rails application - ruby-on-rails

[i have customize the devise gem controller in my application]
[error comes : uninitialized constant SessionsController]
i also copies the view in to the separate section but still it comes

in your routes.rb must be devise_for like this
devise_for :users, controllers: { registrations: 'users/registrations', sessions: 'users/sessions'}

Related

Rails Devise, how to correctly nest resources

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

How to configure routes for different user models using devise?

I have two different user groups, User and Flyer.
I have generated views and controllers for both the models using,
rails g devise:controllers users/flyers
and for views:
rails g devise:views users/flyers
This is my routes.rb:
Rails.application.routes.draw do
devise_for :flyers
devise_for :admins
resources :currencies
resources :broadcasts
devise_for :users, controllers: {
sessions: 'users/sessions',
registrations: 'flyers/registrations'
}
devise_for :flyers, controllers: {
sessions: 'flyers/sessions',
}
end
But I am getting error for devise for flyers controllers route:
Invalid route name, already in use: 'new_flyer_session' 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. For the latter, you can restrict the routes created with `resources` as explained here: http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
How can I have different routes?
Thanks
Remove devise_for :flyers from top

Two models with login

I'm developing an app that at this moment has only one model with login, called reader.
But in the future, there will be another model called company that will require login as well.
So I'm thinking what's the best way to develop it.
I thought that having a model called login with:
email
password
models reader
company inherit from it
but I have no idea if it's the best way to do it.
I'm not using any gem like Devise.
I'm developing my own login system.
So, what do you recommend?
Whats the best way?
Thanks so much!
When the different users that use the application have completely different experience what I use is devise
in your Gemfile
gem "devise"
then you install
rails generate devise:install
then you create your models
rails generate devise user
rails generate devise manager
Here is the key in your routs you can do something like this
devise_for :users, :controllers => {
registrations: 'users/registrations',
sessions: 'users/sessions',
passwords: 'users/passwords',
confirmations: 'users/confirmations'
}
authenticate :user do
namespace :users do
...
root :to => 'dashboards#index'
end
end
devise_for :managers, :controllers => {
registrations: 'managers/registrations',
sessions: 'managers/sessions"'
passwords: 'managers/passwords',
confirmations: 'managers/confirmations'
}
authenticate :manager do
namespace :managers do
...
root :to => 'dashboards#index'
end
end

Adding omniauth to devise routes

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"
}

rails routing devise parameters

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>

Resources