dimanche 23 août 2015

Add model administration to Active Admin - Rails 3

I'm fairly new to Rails and ActiveAdmin.

I'd like to have an interface much like Django's admin, with my app models, so I can administer products, and other stuff.

So far I have the admin_users url where I can add or delete admin users to my app, that's wonderful.

I'm using Rails 3, and I was wondering if I can add a new menu besides Users so I can manage other models from the dashboard

I've tried rails generate active_admin:resource Product

It creates a file called product.rb on app/admin/ but it doesn't works, this is my Product model product.rb

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?

Aucun commentaire:

Enregistrer un commentaire