Gem Rails 4.2 出现 NoMethodError - undefined method `param_key' for nil:NilClass

stephen · 2015年03月16日 · 最后由 lissdy 回复于 2016年09月09日 · 2671 次阅读

使用 rails-simple-search 这个 gemhttps://github.com/yzhanginwa/rails-simple-search 用作搜索,但是在 rails 4.2 报错,出现一下错误:

NoMethodError - undefined method `param_key' for nil:NilClass:
  actionview (4.2.0) lib/action_view/helpers/form_helper.rb:433:in `form_for'

应该是这里出问题

@search = Search.new(User, params[:search])

<% form_for @search, url => "/xxxxxx" do |f| %>

在 google 搜索过, http://stackoverflow.com/questions/27429276/rails-4-and-form-for-undefined-method-param-key-for-nilnilclass

Hey I figured it out.. Style belongs to :model which is throwing an error because of some .model_name stuff in Rails 4 .. That was a poor choice for a model name! Now to rewrite my db, model, controllers, views, etc 

但是我不知道具体问题出现在他代码哪里?要怎么修改? 请教大家!

1 楼 已删除

我们项目也遇到了这个问题,原因是 Search 这个类有一个 model_name 属性,这个属性在 rails4 中被作为关键字用掉咯。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号