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
Related
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.
In a Rails app, I use devise to manage my users and my link to destroy a session no longer work. It was working, and now I have add active admin, It doesn't.
My link is
<%= link_to "Déconnexion", destroy_user_session_path, :method => :delete, :class => 'button' %>
My routes.rb
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks"}
My rake routes
destroy_user_session DELETE /users/sign_out(.:format)
And it try to open the view /users/sign_out, so I have :
ActiveRecord::RecordNotFound in UsersController#show
Couldn't find User with id=sign_out
Does Active_admin and Devise crash together?
It will be weird 'cause active use devise, no?
Edit:
For the next person who will have this issue, I solved it by adding the next line to /config/initializers/devise.rb.
config.sign_out_via = :get
Not exactly the finest way, but it does the job.
Posting Jeff Paquette's comment as an answer.
Update the config/initializers/active_admin.rb with:
config.logout_link_method = :delete
Please make changes in your routes.rb :-
devise_scope :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks"} do
get "/users/sign_out", :to => "devise/sessions#destroy"
end
I am also getting same problem, only this can resolve me after 1hr time wasting.
Thanks.
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
On a rails 3 app, I've got these routes defined:
devise_for :users, :controllers => {:omniauth_callbacks => "users/omniauth_callbacks", :registrations => 'registrations'}, :path_names => { :sign_in => 'login', :sign_out => 'logout' } do
get 'login' =>'devise/sessions#new', :as => :new_user_session
post 'login' => 'devise/sessions#create', :as => :user_session
get 'signup' => 'registrations#new', :as => :new_user_registration
get 'signout' => 'devise/sessions#destroy', :as => :destroy_user_session
end
# catchall route to deal with routing errors
match "*path" => "error#index"
However, now when I go to log /user/auth/facebook, it routes me to the errors page...
My solution to this was to add constraints to the final match:
match "*path" => "error#index", :constraints => lambda {|req| !req.path.starts_with?("/users/auth/") }
This works, but I am wondering if there is a better way... ?
I think you are better off letting a 404 page handle routing errors. You only get a 500 error in development. It's a 404 in production. For example on my site: http://agmprojects.com/test. So i suggest using the 404.html in the public folder instead, rather than loading that controller. Out of curiosity, are you responding with a 404 http status code?
Consider this as a challenge rather than its general approach. The reason I mention this is because, it is generally preferred to incorporate admin-accessible features into the public facing site. This is what's required:
Devise model for Users, visitors accessing the public facing site
Devise model for Admins
Namespace or scope the admin 'area' to /admin. Admins can only login from this route.
Users can sign up directly from the site's public facing landing page; they are not forced to visit /users/sign_up as per the default devise generated route.
Consider overriding the default devise controllers
Thanks,
Mike.
The following seems like I've made some progress in the right direction; this at least provides identical out-of-the-box devise functionality for both users and admins, with the custom routing,
match 'admin', :controller => 'admin'
namespace :admin do
# to be updated later...
end
devise_for :users
#devise_for :admins, :path => "admin" # this works but uses the default
# Devise::SessionController
devise_for :admins,
:controllers => {
:sessions => "admin/sessions",
:passwords => "admin/passwords",
:registrations => "admin/registrations" }, :path => "admin",
:skip => [:sessions, :passwords, :registrations] do
get 'admin/sign_in' => 'admin/sessions#new', :as => :new_admin_session
post 'admin/sign_in' => 'admin/sessions#create', :as => :admin_session
get 'admin/sign_out' => 'admin/sessions#destroy', :as => :destroy_admin_session
get 'admin/sign_up' => 'admin/registrations#new', :as => :new_admin_registration
get 'admin/account' => 'admin/registrations#edit', :as => :edit_admin_registration
post 'admin/account' => 'admin/registrations#create', :as => :admin_registration
get 'admin/cancel' => 'admin/registrations#cancel', :as => :cancel_admin_registration
put 'admin/account' => 'admin/registrations#update'
delete 'admin/account' => 'admin/registrations#destroy'
post 'admin/password' => 'admin/passwords#create', :as => :admin_password
get 'admin/password/new' => 'admin/passwords#new', :as => :new_admin_password
get 'admin/password/edit' => 'admin/passwords#edit', :as => :edit_admin_password
put 'admin/password' => 'admin/passwords#update'
end
Ideas?
caveat: in this example, I've included the :registerable devise module in the Admin model just for testing during development. The sign_up route will, ultimately, be removed.
Much searching yielded (mind the pun) the following blog post that seems to indicate overriding a devise controller requires the re-mapping of all its specified 'HTTP verbs' as it were; this makes sense as unmapped ones would be handled by the default devise controller.
If anyone has more experience working with multiple devise models and the separated admin approach, I would be very much interested in your thoughts and suggestions!