Installing Active Admin and getting an ArgumentError - ruby-on-rails

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.

Related

Ruby on Rails - Should I separate the dashboard for each use type or just have one?

I'm setting up my first rails application and I have a question for an experienced developer. I use devise for my user authentication system. I'm not up on the verbiage yet, so forgive me.
The user will have a dashboard when they log in. Is it better to use the generate scaffold tool to setup a single controller for the dashboard (and use if statements to differentiate), or create the dashboard page under the /students and /teachers (having two separate controllers)?
I'm looking to avoid wasting time or having to backtrack my application if I notice one method won't allow me to achieve something down the road. I'm leaning towards separating them.
Here is my rake routes for you to see how I've got stuff setup so far:
rake routes
Prefix Verb URI Pattern Controller#Action
landing_index GET /landing/index(.:format) landing#index
new_teacher_session GET /teachers/sign_in(.:format) devise/sessions#new
teacher_session POST /teachers/sign_in(.:format) devise/sessions#create
destroy_teacher_session DELETE /teachers/sign_out(.:format) devise/sessions#destroy
teacher_password POST /teachers/password(.:format) devise/passwords#create
new_teacher_password GET /teachers/password/new(.:format) devise/passwords#new
edit_teacher_password GET /teachers/password/edit(.:format) devise/passwords#edit
PATCH /teachers/password(.:format) devise/passwords#update
PUT /teachers/password(.:format) devise/passwords#update
cancel_teacher_registration GET /teachers/cancel(.:format) devise/registrations#cancel
teacher_registration POST /teachers(.:format) devise/registrations#create
new_teacher_registration GET /teachers/sign_up(.:format) devise/registrations#new
edit_teacher_registration GET /teachers/edit(.:format) devise/registrations#edit
PATCH /teachers(.:format) devise/registrations#update
PUT /teachers(.:format) devise/registrations#update
DELETE /teachers(.:format) devise/registrations#destroy
new_student_session GET /students/sign_in(.:format) devise/sessions#new
student_session POST /students/sign_in(.:format) devise/sessions#create
destroy_student_session DELETE /students/sign_out(.:format) devise/sessions#destroy
student_password POST /students/password(.:format) devise/passwords#create
new_student_password GET /students/password/new(.:format) devise/passwords#new
edit_student_password GET /students/password/edit(.:format) devise/passwords#edit
PATCH /students/password(.:format) devise/passwords#update
PUT /students/password(.:format) devise/passwords#update
cancel_student_registration GET /students/cancel(.:format) devise/registrations#cancel
student_registration POST /students(.:format) devise/registrations#create
new_student_registration GET /students/sign_up(.:format) devise/registrations#new
edit_student_registration GET /students/edit(.:format) devise/registrations#edit
PATCH /students(.:format) devise/registrations#update
PUT /students(.:format) devise/registrations#update
DELETE /students(.:format) devise/registrations#destroy
root GET / landing#index
So again, do you think it's better to have both the student's dashboard and the teacher's dashboard be separate, or just have one dashboard and use if statements to differentiate based on the user's type (using 0 & 1 to indicate whether they are a student or teacher)?
Thanks in advance!
If the data that you want to display to each type of user are similar, you could use the same controller and load different partials based on the type of the user.

Devise is installed but no methods are found

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.

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

Rails understands GET request but not POST request

When I access /users/registration/sign_up in my app via the browser (GET) a page renders. When I do the same thing via POST (either by submitting a form w/ the target /users/registration/sign_up or with ajax) my app returns the following error:
Unknown action
The action 'registration' could not be found for UsersController
I am using devise for authentication and creating a devise route for my User model using:
devise_for :users
This path should route to the devise/registrations_controller where i expect it to execute the new method (it currently does for a GET request). Maybe rails, understanding the request is a POST request automatically directs it to the create method but I don't think this is the issue because I start the debugger first thing in the create method and the debugger is not starting in my terminal before I receive this error.
Can anyone with experience with devise decipher what's going on? I'm happy to provide more info if necessary. Thanks.
Devise adds routes to your Rails app, which you can see by running rake routes from a terminal:
new_user_session GET /users/sign_in(.:format)
user_session POST /users/sign_in(.:format)
destroy_user_session GET /users/sign_out(.:format)
user_password POST /users/password(.:format)
new_user_password GET /users/password/new(.:format)
edit_user_password GET /users/password/edit(.:format)
PUT /users/password(.:format)
user_registration POST /users(.:format)
new_user_registration GET /users/sign_up(.:format)
edit_user_registration GET /users/edit(.:format)
PUT /users(.:format)
DELETE /users(.:format)
root /(.:format)
And as you discovered, there is a GET /users/sign_up but no POST /users/sign_up. When creating Devise expects POST /users, for which you can use the helper method user_registration_path. This gets handled by Devise::RegistrationsController#create.

NoMethodError in Devise::Registrations#new on sign up with Devise and Refinery Cms 3.0

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

Resources