Skip to content

Instantly share code, notes, and snippets.

@stungeye
Last active November 17, 2021 17:32
Show Gist options
  • Save stungeye/dabee7e389ac45d97314486abc90f221 to your computer and use it in GitHub Desktop.
Save stungeye/dabee7e389ac45d97314486abc90f221 to your computer and use it in GitHub Desktop.
Installing Active Admin With Rails 5

Active Admin and Git Challenge

Let's create a demo app Rails 5 app using Active Admin. We can also practice using git along the way.

  1. Create a new Rails app.
  2. Initialize the Rails app folder as a git repository.
  3. Add and commit the existing Rails app files/folders to your git repo.
  4. Create a new git branch called adding_models
  5. Generate a Category model: rails g model Category name:string
  6. Add and commit using git.
  7. Generate a Product model: rails g model Product name:string price:decimal category:references
  8. Ensure that the belongs_to and has_many declarations are present in the Product and Cateogory model classes.
  9. Run your db migrations.
  10. Add and commit using git.
  11. Checkout your master git branch and git in your adding_models branch.
  12. Create a new git branch called adding_activeadmin
  13. Edit the Gemfile to add the following
  • gem 'inherited_resources', git: 'https://github.com/activeadmin/inherited_resources'
  • gem 'activeadmin', git: 'https://github.com/activeadmin/activeadmin'
  • gem 'devise'
  1. Run: bundle install
  2. Run: rails g active_admin:install
  3. Run: rails g active_admin:resource Product
  4. Run: rails g active_admin:resource Category
  5. Edit the product.rb and category.rb files in the app/admin folder to permit all columns to be editable from active admin. (Don't forget the category_id column for the product.)
  6. Run: rails db:migrate
  7. Run: rails db:seed
  8. Run: rails s -b 0.0.0.0
  9. Try loading http://localhost:3000/admin and logging in as [email protected] with a password of password.
  10. Add two categories using the admin dashboard.
  11. Add three products assigning each one a category.
  12. If everything was successfull, kill server and switch back to the master branch. Merge in the adding_models changes.
  13. Create a remote repository on github and link it to your local git repo.
  14. Push your local repo to the github repo.
  15. Submit a zip of your repo to the dropbox and sumbit the github repo URL in the dropbox comment textarea.
  16. Grin.
@gsum
Copy link

gsum commented Nov 15, 2018

the command rails g active_admin:install hung up. No progress after that

@codydotio
Copy link

@gsum I was able to get past that by running rails g devise:install before rails g active_admin:install

Since it broke everything running rails g active_admin:install I had to run rails destroy active_admin:install and then remove the activeadmin lines from routes.rb

@ManuelKu1223
Copy link

I can't run the active admin.
When I run rails s there are some issues..

Exiting
Traceback (most recent call last):
	90: from bin/rails:3:in `<main>'
	89: from bin/rails:3:in `load'
	88: from /Volumes/Data2/upwork_ruby_task/hatornot/bin/spring:15:in `<top (required)>'
	87: from /Volumes/Data2/upwork_ruby_task/hatornot/bin/spring:15:in `require'
	86: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
	85: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
	84: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
	83: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
	82: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
	81: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
	80: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
	79: from /Volumes/Data2/upwork_ruby_task/hatornot/bin/rails:9:in `<top (required)>'
	78: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
	77: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
	76: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
	75: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
	74: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
	73: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands.rb:18:in `<main>'
	72: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/command.rb:46:in `invoke'
	71: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/command/base.rb:65:in `perform'
	70: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
	69: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
	68: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
	67: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:142:in `perform'
	66: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:142:in `tap'
	65: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:147:in `block in perform'
	64: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:51:in `start'
	63: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:89:in `log_to_stdout'
	62: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/server.rb:354:in `wrapped_app'
	61: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:27:in `app'
	60: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/server.rb:219:in `app'
	59: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/server.rb:319:in `build_app_and_options_from_config'
	58: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb:40:in `parse_file'
	57: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb:49:in `new_from_string'
	56: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb:49:in `eval'
	55: from config.ru:in `<main>'
	54: from config.ru:in `new'
	53: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb:55:in `initialize'
	52: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb:55:in `instance_eval'
	51: from config.ru:3:in `block in <main>'
	50: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require_relative'
	49: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
	48: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
	47: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
	46: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
	45: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
	44: from /Volumes/Data2/upwork_ruby_task/hatornot/config/environment.rb:5:in `<main>'
	43: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
	42: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
	41: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
	40: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
	39: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
	38: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `call'
	37: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each'
	36: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
	35: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
	34: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
	33: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
	32: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
	31: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
	30: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
	29: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/finisher.rb:130:in `block in <module:Finisher>'
	28: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:10:in `execute'
	27: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/file_update_checker.rb:83:in `execute'
	26: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:30:in `block in updater'
	25: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:20:in `reload!'
	24: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:41:in `load_paths'
	23: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:41:in `each'
	22: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/routes_reloader.rb:41:in `block in load_paths'
	21: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
	20: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
	19: from /Volumes/Data2/upwork_ruby_task/hatornot/config/routes.rb:1:in `<main>'
	18: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/route_set.rb:414:in `draw'
	17: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
	16: from /Users/jhu/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-5.2.2/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
	15: from /Volumes/Data2/upwork_ruby_task/hatornot/config/routes.rb:3:in `block in <main>'
	14: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/activeadmin-1.4.3/lib/active_admin.rb:77:in `routes'
	13: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/activeadmin-1.4.3/lib/active_admin/application.rb:148:in `routes'
	12: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/activeadmin-1.4.3/lib/active_admin/application.rb:122:in `load!'
	11: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/activeadmin-1.4.3/lib/active_admin/application.rb:122:in `each'
	10: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/activeadmin-1.4.3/lib/active_admin/application.rb:122:in `block in load!'
	 9: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/activeadmin-1.4.3/lib/active_admin/application.rb:130:in `load'
	 8: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/activeadmin-1.4.3/lib/active_admin/error.rb:41:in `capture'
	 7: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/activeadmin-1.4.3/lib/active_admin/application.rb:130:in `block in load'
	 6: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
	 5: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
	 4: from /Volumes/Data2/upwork_ruby_task/hatornot/app/admin/products.rb:1:in `<main>'
	 3: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:56:in `load_missing_constant'
	 2: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:74:in `rescue in load_missing_constant'
	 1: from /Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:8:in `without_bootsnap_cache'
/Users/jhu/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:74:in `block in load_missing_constant': uninitialized constant Product (NameError)

I think this is depend on the routes.
How can I fix this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment