2017-10-12 197 views
1

這裏新增了rails。我收到@name的值的空值接收#Profile :: ActiveRecord_Relation:0x00007f3dec9ae7b0將值從控制器傳遞到視圖rails


控制器

def index 
    @name = Profile.where(session[:id]) 
end 

指數HTML

<%= form_for :value, url: value do |f| %> 
    <!------ This form_for is for the post/create into the another table----> 
     <%= f.hidden_field :message, :value => @name %> 

我有一個form_for發佈一個值到另一個表中幷包含一個hidden_​​field以插入到另一個表中。基本上我想檢索這個人的名字,並把名字分配給:value => @name。但它給出了不同的價值。非常感謝您的幫助

+1

'where(session [:id])''沒有任何意義。你的意思是'find(session [:id])'? – meagar

回答

0

要略過簡化,where返回多個值,以ActiveRecord關係的形式。

你想找到一個值,等你where結果使用.first或使用find

相關問題