Let's create a demo app Rails 5 app using Active Admin. We can also practice using git along the way.
- Create a new Rails app.
- Initialize the Rails app folder as a git repository.
- Add and commit the existing Rails app files/folders to your git repo.
- Create a new git branch called
adding_models
- Generate a Category model:
rails g model Category name:string
- Add and commit using git.
- Generate a Product model:
rails g model Product name:string price:decimal category:references
- Ensure that the
belongs_to
andhas_many
declarations are present in the Product and Cateogory model classes. - Run your db migrations.
- Add and commit using git.
- Checkout your master git branch and git in your
adding_models
branch. - Create a new git branch called
adding_activeadmin
- 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'
- Run:
bundle install
- Run:
rails g active_admin:install
- Run:
rails g active_admin:resource Product
- Run:
rails g active_admin:resource Category
- Edit the
product.rb
andcategory.rb
files in theapp/admin
folder to permit all columns to be editable from active admin. (Don't forget thecategory_id
column for the product.) - Run:
rails db:migrate
- Run:
rails db:seed
- Run:
rails s -b 0.0.0.0
- Try loading http://localhost:3000/admin and logging in as
[email protected]
with a password ofpassword
. - Add two categories using the admin dashboard.
- Add three products assigning each one a category.
- If everything was successfull, kill server and switch back to the master branch. Merge in the
adding_models
changes. - Create a remote repository on github and link it to your local git repo.
- Push your local repo to the github repo.
- Submit a zip of your repo to the dropbox and sumbit the github repo URL in the dropbox comment textarea.
- Grin.
@gsum I was able to get past that by running
rails g devise:install
beforerails g active_admin:install
Since it broke everything running
rails g active_admin:install
I had to runrails destroy active_admin:install
and then remove the activeadmin lines from routes.rb