0

I've got a large data model in a Rails application that I'm trying to make serializable and output to JSON. I defined the #serializable_hash method on the model and blacklisted a few attributes. My goal is to whitelist attributes on the controller layer to accept back that same structure and simply ignore values that I don't want "accessible".

One such attribute is giving me trouble when I PUT update with the aforementioned JSON. I get an error while parsing request parameters:

SyntaxError (/Users/brad/.rvm/gems/ruby-1.9.3-p194@project-rails32/gems/actionpack-3.2.13/lib/action_dispatch/http/request.rb:261: syntax error, unexpected tINTEGER, expecting $end ...02933", "software_date"=>"09/05/14", "software_version"=>"10... ... ^): # stack trace... 

As far as Rails is concerned, this is just a string right? Why is it expecting an end of input here? For the record, taking this attribute out before submitting my request results in a successful update, so I'm sure this is what's causing the issue.

    1 Answer 1

    1

    Turns out I'm the unluckiest guy in the world.

    Familiarize yourself with Ruby's %Q() method, and you'll understand where I'm at.

    Under my very very specific case, when Rails is parsing params for a request:

    1. in JSON format
    2. which has a key mapping to an Array
    3. and any value under that Array contains a '/'

    the parse will fail. Why?

    My version of Rails (3.2.13) uses the AwesomePrint library version 0.3.2 when parsing out parameters for the params hash. The #grep method for that version of the gem evaluates matches using:

    %Q/#{match}/ 

    Simply because the specified delimiter is a '/', the evaluation fails and parsing crashes. DO NOT LET THIS HAPPEN TO YOU.

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.