如何从first_name
获取@message
的值,并将其作为@insert message
参数的值传递。
类似于(:message => @message.first_name + 'Your request was submitted')
但我在使用此代码时出错,未定义的方法`first_name'用于#Friend :: ActiveRecord_Relation:0x00000000020be468
@message = Friend.joins(user: :message).select("user.first_name, user.last_name").where(user_id: 1)
@insert = Person.new(:message => 'Your request was submitted')
答案 0 :(得分:0)
@message = Friend.joins(user: :message).select("users.first_name as first_name, users.last_name as last_name").where(user_id: 1)
@insert = Person.new(:message => "#{@message.first.first_name} Your request was submitted")