我正在尝试利用ActiveAdmin应用程序上的number_to_currency助手来显示以磅为单位的数量。
我已经尝试了以下代码并且它会抛出错误。
column "GBP", :sortable => "GBP" do |dailydeal|
number_to_currency (dailydeal.currency_GBP, unit: "£")
end
我试过玩“和”但它仍然会引发错误。
当我不添加:unit => £)它工作正常。
错误讯息:
/home/action/workspace/myapp/app/admin/dailydeal.rb:38:语法错误,意外',',期待')'number_to_currency(dailydeal.currency_GBP,:unit =>“£”)^ /home/action/workspace/myapp/app/admin/dailydeal.rb:38:语法错误,意外')',期待keyword_end /home/action/workspace/myapp/app/admin/dailydeal.rb:65:语法错误,意外的输入结束,期待keyword_end
我正在使用ActiveAdmin pre 1.0和Rails 4.1.4
感谢您的帮助!
以下完整代码:
ActiveAdmin.register Dailydeal, :as => "Daily Deal" do
scope :all, :default => true
scope :AboveAverage
scope :BelowAverage
config.sort_order = "EndDate_desc"
index do
column "Product Name" do |dailydeal|
link_to dailydeal.ProductName, dailydeal.ProductLink, :target => "_blank"
end
column "Unit Price", :UnitPrice
column "Unit Sold", :UnitSold
column "Average Percentage", :sortable => "Average Percentage" do |dailydeal|
number_to_percentage dailydeal.averagechange_UnitSold
end
column "Start Date", :StartDate
column "End Date", :EndDate
column :Revenue, :sortable => :Revenue do |dailydeal|
div :class => "revenue" do
number_to_currency dailydeal.Revenue
end
end
column "Image" do |dailydeal|
link_to (image_tag dailydeal.ImageURL), dailydeal.ImageURL, :target => "_blank", class: 'fancybox'
end
column :Company
column :Country
column "GBP", :sortable => "GBP" do |dailydeal|
number_to_currency (dailydeal.currency_GBP, unit: "£")
end
end
column "EUR", :sortable => "EUR" do |dailydeal|
number_to_currency (dailydeal.currency_EUR)
end
actions
end
filter :ProductName, :label => "Search", :as => :string, filters: ['contains']
filter :UnitPrice, :label => "Unit Price"
filter :Revenue
filter :Company, :as => :select
# filter :StartDate, :label => "Start Date", :as => :date
# filter :EndDate, :label => "End Date", :as => :date
permit_params :ProductName, :ProductLink, :ImageURL, :UnitPrice, :UnitSold, :StartDate, :EndDate, :Revenue, :Company, :Country, :Merchant
# sidebar :Currencies do
# f.input :design, :as => :select, :collection => ["a","b","c"]
# end
end
答案 0 :(得分:2)
下面是正确的代码,我只需要删除number_to_currency和(
之间的空格column "GBP", :sortable => "GBP" do |dailydeal|
number_to_currency(dailydeal.currency_GBP, unit: "£")
end