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:inblock 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:inexecutehook'        /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:ineach'        /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:inblock 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:inload'        /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:ineach'        /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:ininstanceexec'        /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:inblock 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:inruninitializers'        /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:inmethodmissing'        /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:inrequire'        /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:inloaddependency'        /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:inrequireenvironment!'        /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:inblock (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:ininvokeorrebootraketask'        /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.