Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby ActiveAdmin计算_Ruby_Ruby On Rails 4_Activeadmin - Fatal编程技术网

Ruby ActiveAdmin计算

Ruby ActiveAdmin计算,ruby,ruby-on-rails-4,activeadmin,Ruby,Ruby On Rails 4,Activeadmin,我想对我的管理界面进行一些计算,所以我有一个产品资源,在这个资源中,您可以看到我所做的服务列表,例如喷枪,应用程序的价格被视为(1美元/1平方厘米) 我怎样才能更好地实现这个想法 我希望看到,当用户按下按钮“New Product”(新产品)时,它是一个字段,他在该字段中写入平方厘米的数量,并根据这些尺寸,自动以货币呈现所需的金额 Rails 4.1.0 ActiveAdmin 1.0.0 ruby 2.1 刚才你只能输入一个固定价格,比如一个产品/服务的固定价格 app/admin/pro

我想对我的管理界面进行一些计算,所以我有一个产品资源,在这个资源中,您可以看到我所做的服务列表,例如喷枪,应用程序的价格被视为(1美元/1平方厘米

我怎样才能更好地实现这个想法

我希望看到,当用户按下按钮“New Product”(新产品)时,它是一个字段,他在该字段中写入平方厘米的数量,并根据这些尺寸,自动以货币呈现所需的金额


Rails 4.1.0

ActiveAdmin 1.0.0

ruby 2.1


刚才你只能输入一个固定价格,比如一个产品/服务的固定价格

app/admin/product.rb

ActiveAdmin.register Product, { :sort_order => :name_asc } do

    # Scopes
    scope :all, :default => true
    scope :available do |products|
        products.where("available < ?", Date.today)
    end
    scope :drafts do |products|
        products.where("available > ?", Date.today)
    end
    scope :featured_products do |products|
        products.where(:featured => true)
    end

    # Permitted parameters
    permit_params :article_id, :title, :description, :price, :featured, :available, :image_file_name

    # Displayed columns
    index do
    selectable_column
        column :article,  :sortable => :article
        column :title,    :sortable => :title
        column :description
    # Currency helper
        column :price, :sortable => :price do |cur|
            number_to_currency cur.price, locale: :ru
        end
        column :featured
        column :available
    #   column :image_file_name
        actions
    end

    # Product details
    show do
        panel "Product Details" do
            attributes_table_for product do
                row("Article")           { link_to product.article }
                row("Title")             { product.title }
                row("Description")       { product.description }
                row("Price")             { product.price }
                row("Featured")          { product.featured }
                row("Available on")      { product.available }
                row("Image")             { image_tag("products/" + product.image_file_name) }
            end
        end
    end
    # Filters
    filter :article,      :as => :select
    filter :title,        :as => :select               # :check_boxes (for checkboxes)
    filter :price,        :as => :select
    filter :available,    :as => :select
    filter :featured,     :as => :check_boxes
end
class Product < ActiveRecord::Base

    # Relationship
    belongs_to :article

    # Named Scopes
    scope :available, lambda{ where("available < ?", Date.today) }
    scope :drafts,    lambda{ where("available > ?", Date.today) }

    # Validations
    validates :article, :title, :description, :price, :available, :presence => true
    validates :featured, :inclusion => { :in => [true, false] }
end
class Article < ActiveRecord::Base

    # Relationship
    has_many :products, :dependent => :delete_all

    # Validations
    validates :title, :description, :presence => true

    # Define for display a article for products as article code
    def to_s
        "#{title}"
    end
end
ActiveAdmin.register产品,{:sort\u order=>:name\u asc}do
#范围
作用域:all,:default=>true
经营范围:现有do |产品|
产品。如有(“可用”,日期:今天)
结束
经营范围:产品|
产品。在哪里(“可用>?”,日期。今天)
结束
经营范围:特色|产品做|产品|
产品。其中(:featured=>true)
结束
#允许参数
许可参数:文章id,:标题,:描述,:价格,:特色,:可用,:图像\u文件\u名称
#显示列
索引do
可选列
列:article,:sortable=>:article
列:title,:sortable=>:title
栏目:说明
#货币助手
列:price,:sortable=>:price do | cur|
数字到货币当前价格,地区::ru
结束
专栏:特色
专栏:可用
#列:图像\文件\名称
行动
结束
#产品详情
表演
“产品详细信息”面板
产品do的属性\u表\u
行(“文章”){link_to product.Article}
行(“标题”){product.Title}
行(“说明”){product.Description}
行(“价格”){product.Price}
行(“特色”){product.Featured}
行(“在上可用”){product.Available}
行(“图像”){Image_标记(“products/”+product.Image_文件名)}
结束
结束
结束
#过滤器
过滤器:文章,:as=>:选择
筛选器:title,:as=>:选择#:复选框(用于复选框)
过滤器:价格,:as=>:选择
过滤器:可用,:as=>:选择
过滤器:特色,:as=>:复选框
结束
app/models/product.rb

ActiveAdmin.register Product, { :sort_order => :name_asc } do

    # Scopes
    scope :all, :default => true
    scope :available do |products|
        products.where("available < ?", Date.today)
    end
    scope :drafts do |products|
        products.where("available > ?", Date.today)
    end
    scope :featured_products do |products|
        products.where(:featured => true)
    end

    # Permitted parameters
    permit_params :article_id, :title, :description, :price, :featured, :available, :image_file_name

    # Displayed columns
    index do
    selectable_column
        column :article,  :sortable => :article
        column :title,    :sortable => :title
        column :description
    # Currency helper
        column :price, :sortable => :price do |cur|
            number_to_currency cur.price, locale: :ru
        end
        column :featured
        column :available
    #   column :image_file_name
        actions
    end

    # Product details
    show do
        panel "Product Details" do
            attributes_table_for product do
                row("Article")           { link_to product.article }
                row("Title")             { product.title }
                row("Description")       { product.description }
                row("Price")             { product.price }
                row("Featured")          { product.featured }
                row("Available on")      { product.available }
                row("Image")             { image_tag("products/" + product.image_file_name) }
            end
        end
    end
    # Filters
    filter :article,      :as => :select
    filter :title,        :as => :select               # :check_boxes (for checkboxes)
    filter :price,        :as => :select
    filter :available,    :as => :select
    filter :featured,     :as => :check_boxes
end
class Product < ActiveRecord::Base

    # Relationship
    belongs_to :article

    # Named Scopes
    scope :available, lambda{ where("available < ?", Date.today) }
    scope :drafts,    lambda{ where("available > ?", Date.today) }

    # Validations
    validates :article, :title, :description, :price, :available, :presence => true
    validates :featured, :inclusion => { :in => [true, false] }
end
class Article < ActiveRecord::Base

    # Relationship
    has_many :products, :dependent => :delete_all

    # Validations
    validates :title, :description, :presence => true

    # Define for display a article for products as article code
    def to_s
        "#{title}"
    end
end
类产品?”,Date.today)}
#验证
验证:article、:title、:description、:price、:available、:presence=>true
验证:特征,:包含=>{:in=>[true,false]}
结束
app/models/article.rb

ActiveAdmin.register Product, { :sort_order => :name_asc } do

    # Scopes
    scope :all, :default => true
    scope :available do |products|
        products.where("available < ?", Date.today)
    end
    scope :drafts do |products|
        products.where("available > ?", Date.today)
    end
    scope :featured_products do |products|
        products.where(:featured => true)
    end

    # Permitted parameters
    permit_params :article_id, :title, :description, :price, :featured, :available, :image_file_name

    # Displayed columns
    index do
    selectable_column
        column :article,  :sortable => :article
        column :title,    :sortable => :title
        column :description
    # Currency helper
        column :price, :sortable => :price do |cur|
            number_to_currency cur.price, locale: :ru
        end
        column :featured
        column :available
    #   column :image_file_name
        actions
    end

    # Product details
    show do
        panel "Product Details" do
            attributes_table_for product do
                row("Article")           { link_to product.article }
                row("Title")             { product.title }
                row("Description")       { product.description }
                row("Price")             { product.price }
                row("Featured")          { product.featured }
                row("Available on")      { product.available }
                row("Image")             { image_tag("products/" + product.image_file_name) }
            end
        end
    end
    # Filters
    filter :article,      :as => :select
    filter :title,        :as => :select               # :check_boxes (for checkboxes)
    filter :price,        :as => :select
    filter :available,    :as => :select
    filter :featured,     :as => :check_boxes
end
class Product < ActiveRecord::Base

    # Relationship
    belongs_to :article

    # Named Scopes
    scope :available, lambda{ where("available < ?", Date.today) }
    scope :drafts,    lambda{ where("available > ?", Date.today) }

    # Validations
    validates :article, :title, :description, :price, :available, :presence => true
    validates :featured, :inclusion => { :in => [true, false] }
end
class Article < ActiveRecord::Base

    # Relationship
    has_many :products, :dependent => :delete_all

    # Validations
    validates :title, :description, :presence => true

    # Define for display a article for products as article code
    def to_s
        "#{title}"
    end
end
类文章:全部删除
#验证
验证:title、:description、:presence=>true
#定义将产品的项目显示为项目代码
def至美国
“#{title}”
结束
结束

用户输入维度后,是否要在表单页面上显示价格?在保存之前?