Snippet options not saved correctly [$15]
exocode opened this issue · 0 comments
exocode commented
Before you read on:
*Should I save the snippet options
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
snippet_5: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
name: team_member
options: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
name: sacasc
job: asca
email: scascasc
phone: ''
image_id: '91'
in a seperate DB Table?*
Or can I serialize this in the same db entry as the content (column named snippets and is serialzed)
Please help me out !!!
I have two snippet
-areas on my page with unique ids:
<div class="" data-contenteditable="true" data-mercury="snippets" id="company-team-members-left">/div>
<div class="" data-contenteditable="true" data-mercury="snippets" id="company-team-members-right">/div>
When I drop one option left and one right, save them and refresh the page, the options get saved correctly.
# left
params sent
{"snippet_0"=>{"name"=>"template_test", "options"=>{"name"=>"0"}}}
# mercury_content (persisted)
{"snippet_0"=>{"name"=>"template_test", "options"=>{"name"=>"0"}}}
# after updating snippets
{"snippet_0"=>{"name"=>"template_test", "options"=>{"name"=>"0"}}}
# right
# params sent
{"snippet_1"=>{"name"=>"template_test", "options"=>{"name"=>"1"}}}
# mercury_content (persisted)
{"snippet_1"=>{"name"=>"template_test", "options"=>{"name"=>"1"}}}
# after updating snippets
{"snippet_1"=>{"name"=>"template_test", "options"=>{"name"=>"1"}}}
Now I add one snippet-options to the right, save them again, they submitted parameters are in a completly shuffled order:
# left
# param
{"snippet_0"=>{"name"=>"template_test", "options"=>{"name"=>"3"}}}
# mercury
{"snippet_0"=>{"name"=>"template_test", "options"=>{"name"=>"1"}}}
# after snippets update
{"snippet_0"=>{"name"=>"template_test", "options"=>{"name"=>"3"}}}
# right
# param
{"snippet_1"=>{"name"=>"template_test", "options"=>{"name"=>"3"}}}
# mercury
{"snippet_2"=>{"name"=>"template_test", "options"=>{"name"=>"3"}},
"snippet_1"=>{"name"=>"template_test", "options"=>{"name"=>"2"}}}
# after snippets update
{"snippet_1"=>{"name"=>"template_test", "options"=>{"name"=>"3"}}}
When I refresh the page again, they pop over to the other snippet area.
I save the options of snippets within a serialized single database entry.
def update
if params[:mercury][:content]
params[:mercury][:content].each do |request_item|
return if request_item.is_a? Hash
request_data = request_item[1]
request_id = request_item[0]
c = MercuryContent.where(name: request_id, type: request_data['type']).first_or_create!
request_data[:settings] = request_data.delete('request_data')
# extract snippets
snippets_only = request_data.delete('snippets')
c.update_attributes(request_data)
# I keep the snippets when submitted snippets are empty (mercury seems to be not sending options
c.update_attribute(:snippets, snippets_only) if snippets_only && !snippets_only.empty?
end
end
render text: "" # return for mercury
end
Thank you in advance!!!! (urgent)
--- There is a **[$15 open bounty](https://www.bountysource.com/issues/26746701-snippet-options-not-saved-correctly?utm_campaign=plugin&utm_content=tracker%2F134071&utm_medium=issues&utm_source=github)** on this issue. Add to the bounty at [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F134071&utm_medium=issues&utm_source=github).