I am trying to migrate my rails 3 application to rails 4 version.Below code in routes.rb file for devise gem works properly in rails 3 version but the same code is not working for rails 4 version.
devise_for :users, :controllers => { :passwords => 'passwords'}
# devise_for :users, :controllers => { :invitations => 'invitations' }
devise_for :users
devise_for :users, :path => '', :path_names => {:sign_in => 'login', :sign_out => 'logout'}
devise_for :users do
get "/users/sign_out" => "devise/sessions#destroy", :as => :destroy_user_session
end
In rails 4 version i am getting below errror for the above code.
C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0/lib/action
_dispatch/routing/route_set.rb:409:in `add_route': Invalid route name, already i
n use: 'new_user_session' (ArgumentError)
You may have defined two routes with the same name using the `:as` option, or yo
u 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 explaine
d here:
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
Related
I have a platform built in Ruby on Rails that supports creation of websites with their own content, users etc. I want this route to show the sign in page for devise:
devise_scope :user do
get '/websites/:website_id/users/sign_in' => 'devise/sessions#new', :as => :website_session end
I get error:
No route matches {:action=>"show", :controller=>"websites", :locale=>:en, :id=>nil}
My resources are set up in the routes file as below. What should I change?
devise_for :users, :controllers => {:registrations => "devise/custom/registrations", :sessions => "devise/custom/sessions"}
resources :websites do
resources :users end
Currently I have these two routes in my rake routes output:
user_omniauth_authorize
/users/auth/:provider(.:format)
devise/omniauth_callbacks#passthru {:provider=>/facebook|twitter/}
user_omniauth_callback
/users/auth/:action/callback(.:format)
devise/omniauth_callbacks#(?-mix:facebook|twitter)
What file do I have to change to customize these so the route can read:
user_omniauth_authorize
/admin/manage/:slug/auth/:provider(.:format)
devise/omniauth_callbacks#passthru {:provider=>/facebook|twitter/}
user_omniauth_callback
/admin/manage/:slug/auth/:action/callback(.:format)
devise/omniauth_callbacks#(?-mix:facebook|twitter)
Add the following to your routes.rb file:
devise_for :users, :skip => :omniauth_callbacks
devise_scope :user do
match "/admin/manage/:slug/auth/:provider",
:constraints => { :provider => /facebook|twitter/ },
:to => "devise/omniauth_callbacks#passthru",
:as => :user_omniauth_authorize,
:via => [:get, :post]
match "/admin/manage/:slug/auth/:action/callback",
:constraints => { :action => /facebook|twitter/ },
:to => "devise/omniauth_callbacks",
:as => :user_omniauth_callback,
:via => [:get, :post]
end
Now, this is untested. I copied it from Devise's source code. So there are a couple of problems:
You have to add user to the :as alias, so it's not dynamic.
You have to add the auth providers to the constraints, so it's not dynamic.
I just created rails 3.1 app and updated devise 1.4.7.But When i browse http://localhost:3000/users/sign_up(as indicated in rake routes) ,I get " NoMethodError in Devise/registrations#new " extracted source is line
3: <%= form_for(resource_name, resource, :url => registration_path(resource_name)) do |f| %>.
What is the solution to this?Thank you in advance.
routes.rb
Deals::Application.routes.draw do
devise_for :users
match "/users/sign_up" => "devise/registrations#new"
root :to => "home#index"
end
Use these lines in your routes.rb file.
root :to => "home#index"
devise_for :users
devise_scope :user do
get "sign_in", :to => "devise/sessions#new"
get "sign_out", :to => "devise/sessions#destroy"
get "sign_up", :to => "devise/registrations#new"
end
Restarting the server did it for me. Try it before anything else!
Take out this part in config/routes.rb:
match "/users/sign_up" => "devise/registrations#new"
That's redundant, devise_for :users will add that route.
You can try devise_for :users followed directly by resources :users
Looking for a little helping understanding how this route would work?
New route:
resources :artists do
resources :users
end
entire routes
resources :artists do
resources :users
end
match 'auth/:provider/callback' => 'authentications#create'
resources :authentications
devise_for :admins
match '/admin' => 'RailsAdmin/Main#index'
devise_for :users, :controllers => {:registrations => 'registrations'} do
match '/users/change_password', :to => 'registrations#change_password'
match '/users/edit_account', :to => 'registrations#edit_account'
end
resources :posts do
member do
get :likers
end
collection do
get :search
end
end
resources :relationships, :only => [:create, :destroy]
resources :appreciations, :only => [:create, :destroy]
match '/a_json/:id', :to => 'artists#index'
match '/s_json/:id', :to => 'stores#index'
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
match '/blog', :to => 'pages#blog'
resources :users do
member do
get :following, :followers, :likes
end
end
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
match '/:id' => 'users#show', :constraints => {:id => /[^\/]+/}, :as => :global_user
root :to => "pages#home"
end
This would create nested routes, allowing you to use URLs like /artists/5/users/45, which would call UsersController#show with a parameter artist_id which was 5, and a parameter id which was 45. All of the other usual RESTful routes are also created "nested" under a single artist.
Rails actually has a tool for showing you what routes have been generated: just run rake routes to take a peek.
I followed the setting up devise tutorial, but now when I go to
/users/sign_up
I get
Devise NameError in Devise/registrationsController#new
same if I go to
/users/sign_in
I get
/NameError in Devise/sessionsController#create
I have scrapped my models for errors or typos. I don't really get it because it looks like it is having trouble with the "devise controllers" but there aren't any of those in my /app file, so I assume those files (like on git) are running somewhere in the background.
Any suggestions?
A bit late to answer, but my experience might help someone else out.
I had the same issue with devise & cancan. The solution in my case was simply to restart the server.
Try
devise_for :users, :controllers => {:sessions => 'devise/sessions'}, :skip => [:sessions] do
get '/login' => 'devise/sessions#new', :as => :new_user_session
post '/login' => 'devise/sessions#create', :as => :user_session
get '/logout' => 'devise/sessions#destroy', :as => :destroy_user_session
end
or
devise_for :users, :controllers => {:registrations => "devise/registrations"} do
get '/register' => 'devise/registrations#new', :as => :new_user_registration
end