justinweiss / reactive_resource

ActiveRecord-style associations and miscellaneous fixes for nested ActiveResources
http://rubydoc.info/gems/reactive_resource/frames
MIT License
53 stars 14 forks source link

Gracefully handle attributes = nil on construction #8

Closed cdmicacc closed 11 years ago

cdmicacc commented 11 years ago

This is actually also a bug in ActiveResource, but exists here too: If you do something like

@user = User.new(params[:user])

but params[:user] is not set (is nil, e.g because the user reloaded the page you POSTed to), you'll get an ugly error coming from reactive_resource:

NoMethodError (undefined method `stringify_keys' for nil:NilClass):
app/controllers/users_controller.rb:13:in `new'
app/controllers/users_controller.rb:13:in `create'

Given that e.g. ActiveRecord handles this case nicely, I have made a simple change that lets reactive_resource do likewise.

justinweiss commented 11 years ago

Makes sense, thanks!