Rails - uninitialised constant AdminUser with ActiveAdmin gem - ruby-on-rails

I'm new in Rails and I'll try to install ActiveAdmin to my existing project (Rails 3.2.1).
i've had activeadmin, meta_search, devise and sass-rails in my gemfile. Require devise in the configuration/application.rb.
When I try to run "rails generate active_admin:install" or "rails server", i have an error :
C:/RailsInstaller/Ruby1.9.3/l
ive_support/inflector/methods
connstant AdminUser (NameError)
I dont know how to fix.
Thanks :)

Just delete the following line on routes.rb
devise_for :admin_users, ActiveAdmin::Devise.config
Then rerun
rails g active_admin:install

I got this same error after uninstalling and resintalling activeadmin (as I wanted to remove it from admin_user to install it in my own user).
Solution was to search through my project for "admin", and comment all the code that activeadmin had left after uninstall.
The files where I found activeadmin code were:
routes.rb
schema.rb

Related

Error devise don't generate factory with factory_bot

I'm using rails 5.1.4
devise 4.4.1
factory_bot_rails 4.8.2
rails g devise User
Running via Spring preloader in process 15889
invoke active_record
create db/migrate/20180213152941_devise_create_users.rb
create app/models/user.rb
invoke rspec
create spec/models/user_spec.rb
error factory_bot_rails [not found]
insert app/models/user.rb
route devise_for :users
Thanks for replay, the problem was that in config/application.rb, fixture_replacement need to pass :factory_bot and not factory_bot_rails, reading the doc I see that are distinct gems.

How to add a route to a ruby gem

I've been creating a gem and I need to create a route that maps to a controller in the gem.
I have a file ( config/routes.rb ) which looks like this:
Rails.application.routes.draw do
match "rest/*path" => "bconnected/apis#rest"
end
My controller lives in *app/controllers/bconnected/apis_controller.rb*
My gemspecs file includes all of these files.
I run gem build, and gem install.
I include my gem in the rails Gemfile but when I try to hit that URL I get:
No route matches [GET] "/rest/test"'
Do I need to do anything special for Rails to read my routes.rb file from the gem?

Rails migration error database_authenticatable

-- create_table(:admin_users)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `database_authenticatable' for #
Tasks: TOP => db:migrate
How to solv it? Thanx!
migration
create_table(:admin_users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
t.timestamps
end
have all gems in gemfile and installed
Make sure you have devise in the Gemfile and the bundle is installed.
Answer is simple device team sucks!!!
to solve this need make cnanges in GEMFILE
gem 'devise', "~> 1.5"
because in 1.5 there is database_authenticatable type support and in 2.1.0 there is support of only compatibility not creation of fields with this type
thanx everybody.
If you're just getting started with devise (vs updating from previous verions), you might have missed the following step before doing rake db:migrate
rails generate devise:install
This creates
create config/initializers/devise.rb
create config/locales/devise.en.yml
which define the method rake is complaining about above.
Source:
https://github.com/plataformatec/devise
With Devise 2.0 and newer, the migration helper methods (t.database_authenticatable for example) are not available (as stated on the wiki here ) If you're making a new model for users, just use the devise migration generator like so:
rails g devise admin_users (If you're installing devise on your app)
If you're adding the required fields to an existing user model, you should check this page on the devise wiki.
Check out the main README for devise, which has up-to-date information for installing the latest version of devise on Rails.

Install omniauth rails 2.3.4

I have a rails 2.3.4 app that I'd like to extend with omniauth (0.1.5). When I install omniauth gem using rvm and place require 'omniauth' in the config.rb file I get the following error:
`gem_original_require': no such file to load -- omniauth (MissingSourceFile)
The tutorials suggest using putting it in the gemfile but I am using rails 2.
When I 'gem list' omniauth is available however.
This has taken a couple of (hair-pulling) days and I am not sure how to proceed.
Am I placing the require in the correct place or is there somewhere else I could put it (aside form the obvious :-))?
Any ideas would be great....
EDIT 1: I tried config.gem "omniauth" in your environments.rb file and got
/home/mcaulejj/explorer/config/environment.rb:10: undefined local variable or method `config' for main:Object (NameError)
EDIT 2: Using RVM I updated all gems but I am still getting the same error.....
I'm exasperated at this point.
Cheers Slothihtype
Try config.gem "omniauth" in your environments.rb file.
EDIT
As per comment,
try:
require File.join(File.dirname(__FILE__), 'boot')
#insert the following here, in your config/environment.rb
if Gem::VERSION >= "1.3.6"
module Rails
class GemDependency
def requirement
r = super
(r == Gem::Requirement.default) ? nil : r
end
end
end
end
Add require 'oa-oauth' in your environment.rb file

Rails3 - oauth-plugin problem

I'm trying to use oauth-plugin on a Rails application I'm developing, but I keep running into problems.
To make sure I'm not making any mistake, I started an application from scratch (using Rails 3.0.3). Here are the steps I followed:
Create da new rails application (rails.test)
Edited its Gemfile to include:
gem "oauth-plugin", ">=0.4.0.pre1"
gem "oauth", "0.4.4"
Generated oauth-consumer, by running script/rails g oauth_consumer
Edited oauth_consumers.rb to include my keys for Google integration:
:google=>{
:key=>"anonymous",
:secret=>"anonymous",
:scope=>"https://www.google.com/calendar/feeds/",
:options => {
:site => "http://www.google.com",
:request_token_path => "/accounts/OAuthGetRequestToken",
:access_token_path => "/accounts/OAuthGetAccessToken",
:authorize_path=> "/accounts/OAuthAuthorizeToken"
},
}
Edited routes.rb to add the route for oauth_consumer:
resources :oauth_consumers
Edited application_controller.rb to implement the logged_in? method as follows:
def logged_in?
true
end
Now when I access http://localhost:3000/oauth_consumers/google I get the following error:
uninitialized constant GoogleToken
Does anyone know what causes this error and how can I fix it? GoogleToken is a class that should have been auto generated by oauth-plugin, so I can't tell why I'm getting this uninitialized constant error.
The GoogleToken class doesn't get auto-generated unless you pass "google" to the generator like so:
script/rails g oauth_consumer google
or for rails 3:
rails g oauth_consumer google
Also check to ensure the relationship is set up in the user model like so:
has_one :google, :class_name => "GoogleToken", :dependent => :destroy
Did you remember to run bundle install from terminal after editing your Gemfile? Sounds like your Rails app doesn't know about these gems yet.
I have the same problem, i think a solution could be in this:
https://github.com/pelle/oauth-plugin/blob/master/lib/generators/oauth_consumer/USAGE
You need some sort of authentication like restful-authentication plugin, if you uncomment line 27..29 in your oauth_consumers_controller.rb file, you'll jump to next step!

Resources