Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snippet options not saved correctly [$15] #485

Open
exocode opened this issue Sep 17, 2015 · 0 comments
Open

Snippet options not saved correctly [$15] #485

exocode opened this issue Sep 17, 2015 · 0 comments
Labels

Comments

@exocode
Copy link

exocode commented Sep 17, 2015

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).
@jejacks0n jejacks0n changed the title Snippet options not saved correctly Snippet options not saved correctly [$15] Sep 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants