简体   繁体   English

Rails4强参数抛出NoMethodError

[英]Rails4 Strong params throws NoMethodError

I encountered a strange behavior on one computer only. 我仅在一台计算机上遇到一种奇怪的行为。

When strong params are called like this (example taken from SessionController but it fails everywhere where strong params are used) 当像这样调用强参数时(示例取自SessionController,但在使用强参数的地方均失败)

params.require(:session).permit(:email, :password, :remember)

I receive the following error: 我收到以下错误:

NoMethodError
private method `require' called for<ActiveSupport::HashWithIndifferentAccess:0x000001103230c8>

The code works fine on any other computer(developer and production systems) and also worked on this one before. 该代码可以在任何其他计算机(开发人员和生产系统)上正常工作,并且以前也可以在此计算机上工作。 I am using Mac OS(10.9), Ruby(2.2.0), Rails(4.2.x). 我正在使用Mac OS(10.9),Ruby(2.2.0),Rails(4.2.x)。 I use rbenv as ruby version manager. 我使用rbenv作为ruby版本管理器。

It has to be an issue with my local installation. 我的本地安装一定有问题。 After the problem occured, i reinstalled rails, tried another ruby version, updated all the related tools. 问题发生后,我重新安装了rails,尝试了另一个ruby版本,更新了所有相关工具。

Thank you for your help. 谢谢您的帮助。

In Rails prior to 4.x the controller's params object is a hash with indifferent access whilst in Rails 4+ is an ActionController::Parameters instance. 在4.x之前的Rails中,控制器的params对象是具有无差别访问权限的哈希,而在Rails 4+中则是ActionController :: Parameters实例。 Therefore I suspect the Rails version that is being used in that machine for that project is prior to 4.x. 因此,我怀疑该项目在该机器上使用的Rails版本是4.x之前的版本。

If rails --version outputs something unexpected try reinstalling all gems as defined by your Gemfile.lock by running: 如果rails --version输出意外情况,请尝试通过运行以下命令重新安装Gemfile.lock定义的所有gem:

bundle exec gem pristine --all

in the root folder of your project. 在项目的根文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM