Ruby on rails 4 Rails:param缺失或值为空,因为param显示为#&书信电报;边缘:0xb2535b8>&引用;
我正在为使用表单,并且控制器中表单的名称显示为“#”,但我希望它显示为:edge 这是我的控制器:Ruby on rails 4 Rails:param缺失或值为空,因为param显示为#&书信电报;边缘:0xb2535b8>&引用;,ruby-on-rails-4,form-for,Ruby On Rails 4,Form For,我正在为使用表单,并且控制器中表单的名称显示为“#”,但我希望它显示为:edge 这是我的控制器: def new #some_stuff @edge = Edge.new #some_stuff end def create @edge = Edge.new(edge_params) @edge.save end def edge_params params.require(:edge).permit(:loc
def new
#some_stuff
@edge = Edge.new
#some_stuff
end
def create
@edge = Edge.new(edge_params)
@edge.save
end
def edge_params
params.require(:edge).permit(:location_1_id, :location_2_id)
end
视图:
{:action=>'create'})do | f |%>
-
参数请求:
{“utf8”=>“✓", "真实性标志“=>”等等,
“#”=>{location_1_id”=>“91”,“location_2_id”=>“92”},
“提交”=>“创建边缘”,“操作”=>“创建”,
“控制器”=>“管理/边缘”,“楼层地图”\u楼层id”=>“1”}
所以参数的名称应该是:edge,但它是一个我无法访问的对象
谁能告诉我我错过了什么?
非常感谢您的帮助。您应该像这样在收藏集中使用表单块
<%= f.collection_select(:location_1_id, @location, :id, :record_as_string) %>
(虽然使用
:edge
并不是您出现问题的原因,但我怀疑这是因为您使用了:edge
和@edge
的格式相同。您需要保持一致,使用其中一个或另一个)在此之前我有@edge。这不起作用,所以我试了这个。嗯,你试过:edge
和使用f.collection\u select
?
<%= f.collection_select(:location_1_id, @location, :id, :record_as_string) %>
<%= form_for( @edge, :url => {:action => 'create'}) do |f| %>