轨道字符串表达式



我正在使用 Rails 4 并尝试在我的显示页面中显示货币和金额。

我有一个具有费用、货币和participation_cost属性的模型。费用是布尔值。如果为 true,则应显示货币和费用。

如果项目成本有参与费用,我想显示金额后跟货币,如下所示:

 <% if @project.scope.try(:participant).try(:expenses) == true %>
          <%=  "#{@project.scope.try(:participant).try(:participation_cost)} #{@project.scope.try(:participant).try(:currency)}" %>
         <% else %>
          <%= render :text => "Participants do not receive participation costs or payment" %>

但是,其输出只是参与者成本的数字,没有货币指标。数据库存储了货币。

项目模型具有:

class Project < ActiveRecord::Base
  include RoleModel
  # --------------- associations

  #belongs_to :students, through: :courses, counter_cache: true
  has_many :project_questions#, through: :projects
  has_many :project_answers#, through: :project_questions
  has_one :scope
  accepts_nested_attributes_for :scope
  has_one :educator_project_comment
  has_many :project_student_eois
  belongs_to :educator
  has_many :project_invitations
  has_many :observations
  has_one :approval
  belongs_to :industry
  has_and_belongs_to_many :users

  mount_uploader :hero_image, AvatarUploader
  mount_uploader :link_to_video_proposal, VideoUploader
  # --------------- scopes

谁能看出我做错了什么?

谢谢

Rails 提供了将数字转换为货币格式的帮助程序。默认情况下,它假定货币为美元,但您可以通过传递参数来自定义它。

 number_to_currency(number)

您可以从 http://apidock.com/rails/ActionView/Helpers/NumberHelper/number_to_currency 获得更多详细信息

最新更新