在对象rails之间传递值

时间:2017-10-19 05:06:12

标签: ruby-on-rails ruby

如何从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') 

1 个答案:

答案 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")