Devise is installed but no methods are found - ruby-on-rails

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.

Related

How to route my admin sign up to go to an admin page using Devise?

I first used Devise to create authorization for Users. Then I wanted to create a separate Admin user using Devise. I followed these directions from Devise using Option 1: https://github.com/plataformatec/devise/wiki/How-To:-Add-an-Admin-role.
I created my admin model and migration, added an admin into the database Admin.create(etc...)
I added an admin button on the homepage: <%= link_to "Admin", new_admin_session_path %>
My problem is that I click the admin button, the route does takes me to: http://localhost:3000/admins/sign_in, which is correct, but when I sign in, it goes to http://localhost:3000/users/sign_in. I do have flash messages so the flash message says the admin is signed in successfully. I think it has to do with my routes, because the Devise User and Devise Admin routes are the same. How do I configure this to go to admin views(I'm going to create an admin dashboard) and not mess up Devise Admin authorizations?
Here are my current routes:
Prefix Verb URI Pattern Controller#Action
new_admin_session GET /admins/sign_in(.:format) devise/sessions#new
admin_session POST /admins/sign_in(.:format) devise/sessions#create
destroy_admin_session DELETE /admins/sign_out(.:format) devise/sessions#destroy
admin_password POST /admins/password(.:format) devise/passwords#create
new_admin_password GET /admins/password/new(.:format) devise/passwords#new
edit_admin_password GET /admins/password/edit(.:format) devise/passwords#edit
PATCH /admins/password(.:format) devise/passwords#update
PUT /admins/password(.:format) devise/passwords#update
cancel_admin_registration GET /admins/cancel(.:format) devise/registrations#cancel
admin_registration POST /admins(.:format) devise/registrations#create
new_admin_registration GET /admins/sign_up(.:format) devise/registrations#new
edit_admin_registration GET /admins/edit(.:format) devise/registrations#edit
PATCH /admins(.:format) devise/registrations#update
PUT /admins(.:format) devise/registrations#update
DELETE /admins(.:format) devise/registrations#destroy
deals_index GET /deals/index(.:format) deals#index
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

No route matches [GET] "/sign_in"

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'

Installing Active Admin and getting an ArgumentError

I'm trying to use ActiveAdmin for my first time w/ Rails 4. Upon installing all dependent gems, I try to run the installer, i.e.:
rails generate active_admin:install
Doing so gives me the following error:
in `add_route': Invalid route name, already in use: 'admin_root' (ArgumentError)
However, I don't have any 'admin_root' route in routes.rb so I'm a little confused. Here's the output from running 'rake routes':
Prefix Verb URI Pattern Controller#Action
exams GET /exams(.:format) exams#index
POST /exams(.:format) exams#create
new_exam GET /exams/new(.:format) exams#new
edit_exam GET /exams/:id/edit(.:format) exams#edit
exam GET /exams/:id(.:format) exams#show
PATCH /exams/:id(.:format) exams#update
PUT /exams/:id(.:format) exams#update
DELETE /exams/:id(.:format) exams#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 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
root GET / composer#index
home GET /home(.:format) home#index
GET /exam_db/:exam_name/:chapter_name/:topic_name/:item_name(.:format) exam_db#gateway
exam_db_gateway GET /exam_db/gateway(.:format) exam_db#gateway
Here's the full error:
gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:409:in `add_route': Invalid route name, already in use: 'admin_root' (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. For the latter, you can restrict the routes created with `resources` as explained here:
Also worth noting, if I decide to skip the Devise user class altogether, it works:
rails generate active_admin:install --skip-users
The only problem is, I'm not sure how to configure 'config/initializers/active_admin.rb' if I skip the Devise user class?
Any thoughts as to why this might be happening?
I had the same error when upgrading to rails 4 with ActiveAdmin and it turned out this line was repeated twice in my routes.rb: ActiveAdmin.routes(self) I removed the second instance and the error went away.
In addition to Andre's answer - as a result of the error the assets weren't installed properly. You'll have to run rails g active_admin:assets to get the js/css assets installed in the pipeline.

Rails Devise uninitialized constant Model

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

after_sign_in_path not called

I have simple RoR application with devise.
Here is the output ot rake routes
logout_index GET /logout/index(.:format) logout#index
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
Here is the code in application_controller
class ApplicationController < ActionController::Base
protect_from_forgery
def after_sign_in_path()
abort 'signed'
end
end
The problem is that when a user is signed up the method after_sign_in_path is not executed.
What I miss here ?
I think it should be after_sign_in_path_for. See here.

Resources