我试图对 ruby on rails 进行编辑,但它向我显示了有关编辑的参数错误。我对这个问题感到困惑。
然后,我尝试将不同的参数放入 index.html.erb 但是,它仍然不起作用。例如m.id和m
这是 index.html.erb
<% @methodtypes.each do|m| %>
<tr>
<td><%=m.name %></td>
<td><%=m.desp %></td>
</tr>
<%= link_to "Edit", edit_method_types_path(m.id) %>
<% end %>
<%= link_to "Create Method", new_method_types_path %>
这是我的控制器文件:
class MethodTypesController < ApplicationController
def index
@methodtypes = MethodType.all
end
def show
@methodtype = MethodType.find_by_id(params[:id])
end
def create
@methodtype = MethodType.new(method_params)
@methodtype.save
if @methodtype.save
redirect_to method_types_path
else
render :new
end
end
def edit
@methodtype = MethodType.find_by_id(params[:id])
end
def new
@methodtype = MethodType.new
end
private
def method_params
params.require(:method_type).permit(:name, :desp)
end
这是我的编辑页面,即 edit.html.erb:
<%= form_for @methodtype do |f| %>
<div>
<%= f.label :name %>
<%= f.text_area :name %>
</div>
<div>
<%= f.label :desp %>
<%= f.text_field :desp %>
</div>
<%= f.submit %>
<% end %>
结果应该显示我可以编辑我的文本。但是,它在 MethodTypes#edit 中显示 ArgumentError。谁能给我一些建议,我不知道如何解决这个问题......