Solving problems with rails-api and wrap_parameters
In the 0.0.3 version of rails-api this issue is closed, but for previously generated code that doesn’t work anymore you have to do it manually.
The crash I’m referring to is this one, that just happened to me while updating my gems in BikeShare heroku app:
rake aborted! undefined method wrap_parameters' for ActionController::API:Class /tmp/build_25t936fvt5gh3/config/initializers/wrap_parameters.rb:8:in
block in ' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/activesupport/lazyloadhooks.rb:36:in instance_eval' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:36:in
executehook' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/activesupport/lazyloadhooks.rb:26:in block in on_load' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:25:in
each' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/activesupport/lazyloadhooks.rb:25:in on_load' /tmp/build_25t936fvt5gh3/config/initializers/wrap_parameters.rb:7:in
' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/activesupport/dependencies.rb:245:in load' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in
block in load' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/activesupport/dependencies.rb:236:in load_dependency' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in
load' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/engine.rb:588:in block (2 levels) in <class:Engine>' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/engine.rb:587:in
each' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/engine.rb:587:in block in <class:Engine>' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in
instanceexec' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in run' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:55:in
block in runinitializers' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in each' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in
runinitializers' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:136:in initialize!' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in
methodmissing' /tmp/build25t936fvt5gh3/config/environment.rb:5:in <top (required)>' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in
require' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/activesupport/dependencies.rb:251:in block in require' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in
loaddependency' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/activesupport/dependencies.rb:251:in require' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:103:in
requireenvironment!' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:297:in block (2 levels) in initialize_tasks' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:93:in
block (2 levels) in ' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:60:in block (3 levels) in <top (required)>' /tmp/build_25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:23:in
invokeorrebootraketask' /tmp/build25t936fvt5gh3/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:29:in `block (2 levels) in ' Tasks: TOP => environment (See full trace by running task with --trace)
If we read it carefully, it seems that it cannot find wrapparameters method, so we have to make some changes in the file /config/initializers/wrapparameters.rb, in the first block of code.
We must replace the /config/initializers/wrap_parameters.rb file with this one:
I’ve also posted this workaround in StackOverflow for future reference.