ruby-on-rails - Rails:方法类型中的参数错误#edit
问题描述
我试图对 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。谁能给我一些建议,我不知道如何解决这个问题......
解决方案
错误的编辑 url 路径
它应该是<%= link_to "Edit", edit_method_type_path(m.id) %>而不是 <%= link_to "Edit", edit_method_types_path(m.id) %>
还要检查您的路线文件似乎您正在定义
resource: method_types
改成
resources: method_types
推荐阅读
- javascript - 如果文本是数字,如何将函数应用于所有标签内的文本?
- c# - Azure 函数可选“中间”路由参数
- dictionary - 我如何在java中阅读镶木地板字典
- asp.net-mvc - Syteline 8 中的自定义网页
- sql - 从打包的 .NET 工具运行请求时查询超时已过期
- entity-framework - .net core 2.1 中的实体框架支持
- django - Django - 表单的 ChoiceField 没有立即更新
- arrays - Swift:通过方法传递数组时遇到问题
- linux - 如何调试使用 perl 生成的核心文件?
- javascript - 无法读取未定义的属性“登录” - 测试间谍 - Angular2 +