I have finally gotten the on_the_spot gem working in my rails app, which uses devise for authentication.
But, when a user is logged in, making an edit on the user 'show' page results in them being immediately logged out after the change is made (and saved). My guess is that this is to do with routes.rb?
get "users/index"
get "users/show"
devise_for :users, :controllers => { :registrations => :registrations }
devise_for :users
resources :users
root :to => "home#index"
match '/:id' => 'users#show'
resources :users do
collection do
post :update_attribute_on_the_spot
end
end
Are there any obvious errors in this that would cause my problem? Or should I be looking elsewhere? I'm using Rails 3.0.10 and the latest versions of Devise/on_the_spot.
Many thanks!
Related
I'm using devise for sign up and ActiveStorage for image upload. For the delete/purge function to work I have this route
devise_scope :user do
scope module: :users do
resources :registrations do
member do
delete :delete_image_attachment
end
end
end
end
But another place in my routes file I have this route
devise_for :users, controllers: {:registrations => "users/registrations"
}
It makes some of my pages not working. I have read somewhere that it's because registrations are declared two times. How can I make it work?
Any help would be much appreciated
If you use resources :registrations, only: [] do... that will create the parent route that you need without overwriting any of the routes provided by devise. Allowing you to make your nested routes :D
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
im building a basic ecommerce app to teach myself rails, and ive hit a problem. I had already installed devise and had two user models: 'users' and 'merchants'. I then installed active_admin and setup it's standard 'admin_user' model.
The admin section works as intended however now the view of every resource that active admin has access to has become the admin version.
Even my root now routes to the active admin login (assuming no one's logged in)
Any ideas as to why this is happening?
devise_for :merchants
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
devise_for :users
resources :products
resources :categories
resources :brands
get "static/about"
get "static/contact"
get "static/cookie"
get "static/faq"
get "static/help"
get "static/index"
get "static/privacy"
get "static/terms"
root :to => 'static#index'
The order in which rails parses route priority is from top to bottom so, first created -> highest priority. Active Admin also has a root :to => 'admin#dashboard route so your app is trying to load that as the main root route right now.
Try moving ActiveAdmin.routes(self) below your root :to => 'static#index'
I keep getting this error every time I point my browser to "account/sign_out" (GET request):
Unknown action, Could not find devise mapping for path "/accounts/sign_out"
Here's my route for devise:
devise_for :accounts, :controllers => { :registrations => :accounts }
It must be something trivial, but I don't get it. Documentation says devise already provides an action for signing out and binds it to this exact route "/accounts/sign_out". Please share with me what am I doing wrong?
The output of rake routes shows that the action is mapped:
destroy_account_session GET /accounts/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
The problem was that in routes.rb I also had resources :accounts route declared before devise_for. Therefore, the solution turned out to be to put it after the devise_for declaration:
devise_for :accounts, :controllers => { :registrations => :accounts }
resources :accounts