Active Admin uninitialized constant Admin::DashboardController - ruby-on-rails-3.1

I just migrated a Rails app to 3.1. Active Admin is now 0.6.0. That's my routes.rb
AppName::Application.routes.draw do
root :to => "homepage#index"
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
So root is declared before ActiveAdmin routes. We I start the server in development and I reload the browser I get the ActiveAdmin interface here:
http://localhost:3000/admin
When I reload that URL I get:
uninitialized constant Admin::DashboardController

I found several issues:
assets generator must best execute after an update;
controllers/admin clashes with ActiveAdmin route;
root directive should be define before ActiveAdmin route.
To fix number one:
$> rails generate active_admin:assets
To fix number two:
config.default_namespace = :your_desired_namespace
To fix number three just move root up (in config/routes.rb)

Related

No route matches [GET] "/" when trying to add the gem devise

The error comes with
Please add some routes in config/routes.rb.
routes.rb already has
devise_for :users
I am not sure how to fix this error. I have tried rake routes in the GIT terminal with the result:
rake aborted!
Don't know how to build task 'routes' (See the list of available tasks with `rake --tasks`)
Running in development mode on local server.
So few things:
Firstly, rake routes has been removed - I have no idea why tbh, but it is rails routes now instead.
Secondly, devise is adding its routes, but you still need to have some ohter content that devise is to guard access to. You can create a simple HomeController:
class HomeController < ApplicationController
def show
render html: "home"
end
end
and use this as your root route:
# routes.rb
devise_for ...
root to: "home#show"

Nitrous.IO 'Preview' only showing default page

I cannot see the apps running using 'Preview'.
The Ruby environment with the Rails framework is installed (able to see folders and files generated), and see application being built in Nitrous.IO IDE.
My installation shows I have the following installed:
- ruby 2.1.1p76
- Rails 4.1.0
- git version 2.0.0
- SQLite3
Building a simple blog app, I use the scaffold generator to create the MVC components needed for posts and comments:
1. $ rails generate scaffold post title:string body:text
2. $ rails generate scaffold comment post_id:integer body:text
I create the post and comment database tables using:
1. $ rake db:migrate
2. $ rake routes
3. $ rails server
Using 'Preview' to see app running on WEBrick, only get default webpage which says:
- "Routes are set up in the config/routes.rb"
- "running in development mode and haven't set a root route yet."
config/routes.rb file has the following:
Rails.application.routes.draw.do
resources :comments
resources :posts
# lines 6 -> 59 are comments giving coding examples of routes
end
==>> What do I need to do to 'Preview' Ruby apps??
Based on your comment above, I believe what you need to do is remove the public/index.html file and/or go to the route(s) you have created and specify one of them as root.
Also see this SO question and it's answer(s): deploying to heroku -- can't get rid of the "welcome to rails" default page
After you run rake routes command, it creates all the REST calls for you i.e. GET/POST/PUT/DELETE and as you have already created the scaffold you just need to invoke URL with the paths as /comment or /post and you will be able to access your blog application.
Ex: http://yourhost.com:3000/comment or http://yourhost.com:3000/post.

'gmaps4rails' undefined local variable or method 'acts_as_gmappable' rails 3.2.1 routing error

just playing around with the gem 'gmaps4rails' but I'm getting the following routing error
undefined local variable or method `acts_as_gmappable'
I've performed the following steps:
1) added the following to the Gemfile: gem 'gmaps4rails' and bundled
2) generated scaffold Location
3) added the following to my model, location.rb then db:migrate
class Location < ActiveRecord::Base
attr_accessible :address, :latitude, :longitude
acts_as_gmappable
def gmaps4rails_address
address
end
end
5) changed my root to the following and deleted the old index file
root :to => 'locations#index'
6) added the following to the body of aplication.html.erb
<%= yield :scripts %>
Seems like it can't find the methods in the gem I installed?
I'm using gmaps4rails v2.0.3, ruby v1.9.3, rails 3.2.1
I've looked on similar topics on stackoverflow and performed simple tasks such as restarting server etc but still the same error.
#apneadiving maybe you could help?
Many thanks
Check out the Docs of gmaps4rails, since 2.* version you don't have to add the acts_as_gmappable method.
Now it uses geocoder.
Here is an small tutorial, that explains how it works.

Rails 4: Own engine "No route matches"

I write..
rails new testapp
cd testapp/
rails plugin new blog --mountable
cd blog/
rails g scaffold post name description:text
rake db:migrate
cd ../
rails s
Go to localhost:3000/blog/posts/index and i get error "No route matches [GET] "/blog/posts/index""
What i'm doing wrong?
Putting the engine at some random directory inside your application won't make it magically work. I don't know where you learned this technique from, but it is wrong.
You should put the engine outside your application and require it into your application's Gemfile, like this:
gem 'blog', :path => '../blog'
Then the engine will be automatically loaded by Rails.
The Engines Guide goes into more detail. I highly recommend reading that.

How can fixtures be replaced with factories using rails3-generators?

I'm trying to replace fixture generation with factories using rails3-generators:
https://github.com/indirect/rails3-generators#readme
The gem is included in my Gemfile and has been installed:
# Gemfile
gem 'rails3-generators', :group => :development
I added the following to application.rb:
# application.rb
config.generators do |g|
g.stylesheets false
g.fixture_replacement :factory_girl
end
Yet 'rails g model Insect' is still generating fixtures ('insects.yml'). Is this working for others using Rails 3.0.4 and rails3-generators 0.17.4?
'rails g' shows the new generators available (such as Authlogic and Koala), but 'rails g model' still lists fixtures and doesn't refer to factories.
What else should I add to get this to work? Thanks.
Edit: I ran the gem's test suite, which includes a test for this, and it passes. No clue why it doesn't work with my app.
Edit2: I tried again with a test project and get the same result: fixtures instead of factories. If anybody could confirm whether this works for them with Rails 3.0.4 and rails3-generators 0.17.4, that would be helpful too because it would imply that I'm doing something wrong with my projects.
Edit3: It works if I run 'rails g model Insect -r factory_girl'. I thought the generator configuration in application.rb was supposed to take care of that, so this seems to be the source of the problem.
Searching around I found the following, which may help:
Try specifying a directory option for factory_girl's factories:
config.generators do |g|
g.stylesheets false
g.fixture_replacement :factory_girl, :dir => "spec/factories" # or test/factories, as the case may be
end
If you're using Test::Unit, try the following:
config.generators do |g|
g.stylesheets false
g.test_framework :test_unit, :fixture_replacement => :factory_girl
end
In both cases you will still need the rails3-generators gem, although there is a push to get that functionality into factory_girl_rails.
This Rails bug indicates that, at some point, the g.fixture_replacement code may not have worked right. Perhaps a test in 3.0.5 is in order. :)
A short update 9 years later:
instead of "factory_girl_rails" (which is deprecated now) use "factory_bot_rails".
Now, the factory gets created automagically:
$ rails g model tester name:string
Running via Spring preloader in process 31467
invoke active_record
create db/migrate/20200327152901_create_testers.rb
create app/models/tester.rb
invoke rspec
create spec/models/tester_spec.rb
invoke factory_bot
create spec/factories/testers.rb
I use rails 5.2.4, but this should also work with rails 6.

Resources