-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated admin script form to support new field
:analysis_action_params was not changeable and had no form presence. Fixed it.
- Loading branch information
Showing
6 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# https://gist.github.com/joost/7ee5fbcc40e377369351 | ||
|
||
# Put this code in lib/validators/json_validator.rb | ||
# Usage in your model: | ||
# validates :json_attribute, presence: true, json: true | ||
# | ||
# To have a detailed error use something like: | ||
# validates :json_attribute, presence: true, json: {message: :some_i18n_key} | ||
# In your yaml use: | ||
# some_i18n_key: "detailed exception message: %{exception_message}" | ||
class JsonValidator < ActiveModel::EachValidator | ||
|
||
def initialize(options) | ||
options.reverse_merge!(:message => :invalid) | ||
super(options) | ||
end | ||
|
||
def validate_each(record, attribute, value) | ||
value = value.strip if value.is_a?(String) | ||
ActiveSupport::JSON.decode(value) | ||
rescue MultiJson::LoadError, TypeError => exception | ||
record.errors.add(attribute, options[:message], exception_message: exception.message) | ||
end | ||
|
||
end |