2015-08-24 40 views
4

我是相当新的Rails和ActiveAdmin。添加模型管理到主动管理 - 的Rails 3

我想有像Django的管理接口,与我的应用程序的模型,这样我就可以管理产品,和其他的东西。

到目前为止,我有admin_users网址,我可以添加或删除管理员用户我的应用程序,这是美妙的。

我使用Rails 3,我在想,如果我可以添加用户之外的新菜单,所以我可以从dashboard

我已经试过rails generate active_admin:resource Product

管理其他车型它创建一个文件呼吁app/admin/product.rb但它没有工作,这是我Product模型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 

我不知道,我究竟做错了什么?

任何想法?

+2

嘿检查这个http://railscasts.com/episodes/284-active-admin – Arvind

+0

真棒@Arv书签,非常感谢! – NeoVe

回答

6

要注册Product模式,运行:

rails generate active_admin:resource Product 

这在app/admin/product.rb配置资源创建一个文件。 刷新Web浏览器看到的界面。

请看一看Active Admin Documentation了解更多详情。

+0

是的,我做到了,但之前没有工作,哈哈,非常感谢! – NeoVe

+1

非常欢迎:)我很高兴它现在为你工作:-) –

2

app/admin您product.rb文件中注册的模型。我会看起来像

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 

看看documentation了解更多信息。

+0

谢谢,我将把它作为个人文档,非常感谢! – NeoVe