【发布时间】:2019-09-03 22:54:57
【问题描述】:
我有一个date_field :born_in 年龄,我想在用户个人资料中显示计算出的用户年龄,而不是常规日期格式mm/dd/yyyy
我在这个答案中找到了关于如何计算用户年龄的method,但我不知道如何在我的 Rails 应用程序中实现它。
user_information.rb
class UserInformation < ApplicationRecord
belongs_to :user
has_one :gender, :dependent => :destroy
accepts_nested_attributes_for :gender, :allow_destroy => true
has_one :relationship, :dependent => :destroy
accepts_nested_attributes_for :relationship, :allow_destroy => true
end
show.html.erb
<%= @user.user_information.try(:born_in) %>
【问题讨论】:
-
你试过什么?你的用户模型是什么样的?
-
@moveson 我已将我的模型包含在我的问题中
标签: ruby-on-rails ruby