Created
August 2, 2010 18:37
-
-
Save chrisconley/505094 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
And a form exists with name: "SAT Test Score", form_category: the form category | |
And the following strings exist: | |
| name | column | required | title_field | id | form | visibility_rule_in_json | | |
| Score | SAT_I_MATH_SCORE | true | true | | the form | | | |
| Are you lying? | SAT_II_SUBJECT | true | | 1 | the form | | | |
| Actual Score | SAT_II_SUBJECT_SCORE | true | | | the form | {"rule":'include',"values":["maybe","yes"],"responsible_field_id":'1'} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pickle/world' | |
module Pickle::Session | |
def create_model(pickle_ref, fields = nil) | |
factory, label = *parse_model(pickle_ref) | |
raise ArgumentError, "Can't create with an ordinal (e.g. 1st user)" if label.is_a?(Integer) | |
fields = fields.is_a?(Hash) ? parse_hash(fields) : parse_fields(fields) | |
#my addition | |
fields = allow_json_fields(fields) | |
record = pickle_config.factories[factory].create(fields) | |
store_model(factory, label, record) | |
end | |
#my addition | |
def allow_json_fields(hash) | |
hash.inject({}) do |new_hash, (key, val)| | |
new_key, new_val = key, val | |
if key.to_s =~ /^(.*)_in_json$/ | |
new_key = $1 | |
new_val = val && ActiveSupport::JSON.decode(val) | |
end | |
new_hash.merge new_key => new_val | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment