将模型管理添加到Active Admin - Rails 3

时间:2022-03-13 23:26:23

I'm fairly new to Rails and ActiveAdmin.

我是Rails和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.

我希望有一个类似Django管理员的界面,我的应用程序模型,所以我可以管理产品和其他东西。

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

到目前为止,我有admin_users url,我可以添加或删除管理员用户到我的应用程序,这太棒了。

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

我正在使用Rails 3,我想知道我是否可以在用户之外添加新菜单,以便我可以从仪表板管理其他模型

I've tried rails generate active_admin:resource Product

我已经尝试过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

它在app / admin /上创建一个名为product.rb的文件,但它不起作用,这是我的产品型号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?

2 个解决方案

#1


7  

To register your Product model, run:

要注册您的产品型号,请运行:

rails generate active_admin:resource Product

This creates a file at app/admin/product.rb for configuring the resource. Refresh your web browser to see the interface.

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

Please take a look at Active Admin Documentation for more details.

请查看Active Admin Documentation以获取更多详细信息。

#2


2  

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

在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

Look at the documentation for more info.

查看文档以获取更多信息。

#1


7  

To register your Product model, run:

要注册您的产品型号,请运行:

rails generate active_admin:resource Product

This creates a file at app/admin/product.rb for configuring the resource. Refresh your web browser to see the interface.

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

Please take a look at Active Admin Documentation for more details.

请查看Active Admin Documentation以获取更多详细信息。

#2


2  

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

在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

Look at the documentation for more info.

查看文档以获取更多信息。