Add Model Administration to Active Admin - Rails 3

I am new to Rails and ActiveAdmin.

I would like to have an interface similar to Django admin with my applications, so I can manage products and other things.

As long as I have the admin_users URL where I can add or remove admin users in my application, this is great.

I use Rails 3 and I was wondering if I can add a new menu besides Users so that I can manage other models from dashboard

I tried rails generate active_admin:resource Product

It creates the product.rb file on app/admin/ , but it does not work, this is my Product product.rb model

 class Product < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me belongs_to :category has_many :line_items has_many :orders, through: :line_items validates_presence_of :category_id, :name, :price_cents attr_accessible :avatar has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png" validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/ attr_accessor :price attr_accessible :category_id, :description, :image, :name, :price_cents, :upc_code, :price, :taxable def price price_cents/100.0 if price_cents end def price= price self.price_cents = (price.to_f*100).round end end 

I don’t know what am I doing wrong?

Any ideas?

+4
source share
2 answers

To register a Product model, run:

 rails generate active_admin:resource Product 

This creates a file in app/admin/product.rb to configure the resource. Refresh your web browser to see the interface.

Learn more about Active Admin Documentation .

+6
source

In app/admin your product.rb file will register the model. I would look something like

 ActiveAdmin.register Product do :category_id, :description, :image, :name, :price_cents, :upc_code, :price, :taxable index do selectable_column id_column column :description column :name column :price_cents actions end form do |f| f.inputs "Product Details" do f.input :price f.input :name f.input :description # more fields end f.actions end end 

See the documentation for more information.

+2
source

All Articles