简体   繁体   中英

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)

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). I use rbenv as ruby version manager.

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.

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. Therefore I suspect the Rails version that is being used in that machine for that project is prior to 4.x.

If rails --version outputs something unexpected try reinstalling all gems as defined by your Gemfile.lock by running:

bundle exec gem pristine --all

in the root folder of your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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