My Rails version is 3.2.12. I use following commands to create users authentications:
rails generate devise:install
rails generate devise users
rake db:migrate
and following are my routes
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
But i still cant register new users or login into app even though user email and password are saved on db. Following are errors that i got:
NameError in Devise::RegistrationsController#create
uninitialized constant Model
Where i might be wrong?
try this to change this line for devise.rb
config.sign_out_via = :delete
to
config.sign_out_via = :get
It works for me
Try this in your routes,
devise_for :users, :controllers => {:registrations => "devise/registrations"} do
get '/register' => 'devise/registrations#new', :as => :new_user_registration
end
Related
Set up Authentication with AngularJS and Ruby on Rails. Try to do under this article https://www.airpair.com/ruby-on-rails/posts/authentication-with-angularjs-and-ruby-on-rails. But when run the test with rspec have the same error
Authentication login with valid inputs
Failure/Error: Unable to find matching line from backtrace
ActionController::RoutingError:
No route matches [GET] "/sign_in"
In rake routes have:
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session GET /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
root GET / devise/sessions#new
user_root GET /persons/profile(.:format) persons#profile
next_page GET /index(.:format) persons#index
GET /omniauth/:provider/callback(.:format) devise_token_auth/omniauth_callbacks#redirect_callbacks
As your routes say...you need to use /users/sign_in with GET request.
You are using /sign_in which doesn't exist...
you can directly use new_user_session_path
if you actually want to use /sign_in,edit your routes and add this
get 'sign_in' => 'devise/sessions#new'
I installed Ruby 1.9.3 then Rails 3 then RubyMine 5.4.
I followed the installation guide to install Devise 3.
devise:install
devise user
db:migrate
After that I tried to use the any method from Devise, but none is found, like the method user_signed_in or new_user_session_path etc...
I'm probably missing something very simple...
Edit: Routes.rb
C:\Ruby193\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:\Ruby193\bin\rake routes
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
notes GET /notes(.:format) notes#index
POST /notes(.:format) notes#create
new_note GET /notes/new(.:format) notes#new
edit_note GET /notes/:id/edit(.:format) notes#edit
note GET /notes/:id(.:format) notes#show
PUT /notes/:id(.:format) notes#update
DELETE /notes/:id(.:format) notes#destroy
root / notes#index
Process finished with exit code 0
Edit2:
Well, turns up it is RubyMine. It just won't recognize any Devise functions for some reason...
Although it showing me errors, the app seems to be functional.
Im having problems with signing out with devise, i get the following error message when i try to sign out, its looking for a user with the id=sign_out. Any suggestions?
ActiveRecord::RecordNotFound in UsersController#show
Couldn't find User with id=sign_out
Routes
devise_for :users
match 'users/settings', to: 'users#settings'
resources :users, only: [:show, :update]
Link
<%= link_to 'Logout', destroy_user_session_path, :method => :delete %>
Rake Routes
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
users_settings /users/settings(.:format) users#settings
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format)
Recently I've solved this problem, You need try to put or check the below line in your views/layouts/application.html.erb
<%= javascript_include_tag "application" %>
Also check if you have jquery_ujs in your Gemfile.
Make sure you're actually clicking on the correct link. I highly doubt that link routes the request to UsersController#show. destroy_user_session_path routes to /users/sign_out so this is impossible.
I have a controller of Workers.
If I logged out, I am redirected to: localhost:3000. I want to be redirect to the sign_in of my devise.
this is my rake routes:
users_sign_out GET /users/sign_out(.:format) devise/sessions#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
and this is my routes.rb:
devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end
resources :tasksadmins
resources :workers
root to: "devise/registrations#create"
It is specified in the devise wiki.
https://github.com/plataformatec/devise/wiki/How-To:-Change-the-redirect-path-after-destroying-a-session-i.e.-signing-out
class ApplicationController < ActionController::Base
private
# Overwriting the sign_out redirect path method
def after_sign_out_path_for(resource_or_scope)
new_user_session_path
end
end
In you can override the after_sign_out_path_for helper in your application controller.
def after_sign_out_path_for(resource_or_scope)
# logic here
end
I am trying to Sign up on my app, I get this error
NoMethodError in Devise::Registrations#new
<h2>Sign up</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
undefined method `user_registration_path' for #<ActionDispatch::Routing::RoutesProxy:0x007fb0bc0dc220>
My rake routes output
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
reg GET /reg(.:format) reg#regl
refinery / Refinery::Core::Engine
// much refinery routes
I have already restarted Webrick and performed db:reset db:migrate
Also, when I am trying to access resource with console on web page I get
NameError: undefined local variable or method `resource' for #<ActionDispatch::Routing::RoutesProxy:0x007fb0c2b683a0>
here is my routes.rb
Rails.application.routes.draw do
devise_for :users
# This line mounts Refinery's routes at the root of your application.
# This means, any requests to the root URL of your application will go to Refinery::PagesController#home.
# If you would like to change where this extension is mounted, simply change the
# configuration option `mounted_path` to something different in config/initializers/refinery/core.rb
# We ask that you don't use the :as option here, as Refinery relies on it being the default of "refinery"
mount Refinery::Core::Engine, at: Refinery::Core.mounted_path
end
After 3 days s finaly slove it . add
Devise.setup do |config| config.router_name = :main_app end
in config/initializers/devise.rb