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

stephen · March 16, 2015 · Last by lissdy replied at September 09, 2016 · 2673 hits

使用 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 Floor has deleted

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

You need to Sign in before reply, if you don't have an account, please Sign up first.