Skip to content

Instantly share code, notes, and snippets.

@vmcilwain
Last active August 22, 2019 14:30
Show Gist options
  • Save vmcilwain/c0eef8f2559766e1c9eafedf2937b19c to your computer and use it in GitHub Desktop.
Save vmcilwain/c0eef8f2559766e1c9eafedf2937b19c to your computer and use it in GitHub Desktop.
[Rails] Add serialized data to strong parameters
# Where data is a hash of predefined keys
# This example also shows at the end another hash inside of data
params.permit(
:date_range,
:email,
:enabled,
:id,
:limit,
:match,
:send_day,
:school,
:title,
:token,
data: [
:all_instances,
:description_status,
:featured_only,
:hide_images,
:hide_times,
:hide_view_all,
:include_matching_instances,
:keywords,
:place_ids,
:show_past_events,
:sponsored,
:sponsored_only,
:staff_picks,
:tags,
departments: [],
types: [],
groups: [],
venues: [],
excludes: [
:keywords,
:tags,
types: []
]
]
)
# If we don't care about the attributes in data
# This could be either a hash or an array
params.permit(:title, :send_day, :enabled, :limit, :date_range, :match, data: [])
=begin
Works with code (something like):
Note: Written for liquid template
<fieldset>
<label>
<span>Only Show Featured</span>
<input type="hidden" name="data[featured_only]" value='0'>
<input type="checkbox"
name="data[featured_only]"
id="data[featured_only]"
value="1"
{% if object.data['featured_only'] == '1' %} checked="checked"{% endif %}
>
</label>
</fieldset>
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment