Bugfix for "nested => [:posts]" in ruby 1.9.2 #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bugfix for how the nested parent class is calculated from the :nested option in ruby 1.9.2, which has a different Array#to_s method to previous ruby versions.
Hi Jesse. I've been using your great plugin resource_this for years (thanks!) and have found a problem using it with ruby 1.9.2p0.
When calling resource_this with a nested resource, eg
resource_this :nested => [:reports]
I get an error: "can't convert Symbol into Integer"
I poked around in the plugin code and the problem seems to be how the Array#to_s method is implemented in ruby 1.9.2. In ruby 1.8.7, it behaves like this:
In ruby 1.9.2 it's more like Array#inspect:
ruby-1.9.2-p0 :001 > [:reports].to_s
=> "[:reports]"
This difference makes the following line go wrong:
/vendor/plugins/resource_this/lib.rb:22
unless options[:nested].nil?
nested = options[:nested].to_s.singularize
as it sets the nested variable to "[:reports]", which screws up subsequent attempts to process it with singularize, camelize etc.
If i change the call to
resource_this :nested => :reports
then it works fine.
I'm not sure why the :nested option was ever an array in the first place but i've changed how nested is calculated to work in ruby 1.9.2p0 and older versions, and also to work with being passed an array containing a symbol or a single symbol: the new line is
Cheers, max