将值从控制器传递到视图rails
问题描述:
这里新增了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。但它给出了不同的价值。非常感谢您的帮助
答
要略过简化,where
返回多个值,以ActiveRecord关系的形式。
你想找到一个单值,等你where
结果使用.first
或使用find
。
'where(session [:id])''没有任何意义。你的意思是'find(session [:id])'? – meagar