Devise No method error issue in rails 3.1 - ruby-on-rails-3

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

Related

Custom route for user/admin logins

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

Usernames in route with devise

I'm struggling to get usernames to show in the routes related to devise.
How do I get the following routes to show?
www.blabla.com/username/edit
www.blabla.com/username/event/id
Do I have to declare a scope within a scope? Thanks for the help.
Right now my routes file looks like this
Weplanthings::Application.routes.draw do
resources :vendors
resources :venues
resources :events
get "profiles/index"
get "users/index"
get "users/show"
get 'tags/:tag', to: 'events#index', as: :tag
authenticated :user do
root :to => 'home#index'
end
match '/event/new', :to => 'events#new'
root :to => "home#index"
devise_for :users do
get "/login" => "devise/sessions#new"
match '/login', :to => 'devise/sessions#new'
get "/logout" => "devise/sessions#destroy"
match '/logout', :to => 'devise/sessions#destroy'
get "/edit" => "devise/sessions#edit"
match '/edit', :to => 'devise/sessions#edit'
scope ":username", :as => "user" do
#resources :users
match '/', :to => 'profiles#index'
match '/edit', :to => 'devise/sessions#edit'
match '/event/:id', :to => 'events#show'
end
end
My suggestion is for you to use the friendly_id gem.
It will make much easier to do what you want and just with a single line of code.

Devise, can't log out

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.

Rails 3: What does this route do?

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.

Devise NameError in Devise/registrationsController#new

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