Skip to content

Bugfix for "nested => [:posts]" in ruby 1.9.2#1

Open
toastkid wants to merge 1 commit intojnewland:masterfrom
toastkid:master
Open

Bugfix for "nested => [:posts]" in ruby 1.9.2#1
toastkid wants to merge 1 commit intojnewland:masterfrom
toastkid:master

Conversation

@toastkid
Copy link
Copy Markdown

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:

[:reports].to_s
=> "reports"

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

    nested                = [options[:nested]].flatten[0].to_s.singularize

Cheers, max

… option in ruby 1.9.2, which has a different Array#to_s method to previous ruby versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant