Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8270431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:33:54+00:00 2026-06-08T06:33:54+00:00

I have an observer that serializes a hash and saves it to a mySQL

  • 0

I have an observer that serializes a hash and saves it to a mySQL database as a TEXT field on my User model. The issue I’m having is I’m trying to add a new key/value to existing hash instead of overwriting it. It seems to simply be overwriting it.
Is my merge syntax incorrect?

Here’s my observer:

class NotificationObserver < ActiveRecord::Observer
  observe :event

  def after_update(event)
    usersToNotify=event.following

    usersToNotify.each do |u|               
        u.messages.merge! 'event'=>event.id
        u.save 
    end
  end
end

Any help is appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:33:55+00:00Added an answer on June 8, 2026 at 6:33 am

    It works for me using Ruby 1.9.3 using both literals and implicit hashes. For example:

    [1] pry(main)> foo = {foo: 'bar'}
    => {:foo=>"bar"}
    [2] pry(main)> bar = {bar: 'baz'}
    => {:bar=>"baz"}
    [3] pry(main)> foo.merge! bar
    => {:foo=>"bar", :bar=>"baz"}
    [4] pry(main)> foo.merge! alice: 'bob'
    => {:foo=>"bar", :bar=>"baz", :alice=>"bob"}
    

    You might try using symbols instead of strings for your keys, unless you know you have a HashWithIndifferentAccess. You might also want to make sure you’re passing a hash literal by enclosing your hash in braces just to avoid any ambiguity with the parser.

    There’s probably something else going on, so make sure you update your question with actual error messages and examples if the foregoing suggestions don’t work for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a content observer that polls content://sms/ in android 1.5 so that I
I have a custom observer in Magento 1.6.2.0 that is called when a CMS
I have code similar to this in all my observer classes that handle events
I have a content observer that should be notified when one of the contacts
I have a service running that contains an SQLite DB and a Content Observer
Using Observer pattern. I have a class, called Monitor for example, that is monitoring
I have an object observer that I only need to detect one thing. Once
Is there a way to make an observer that you have custom made have
I have an input field that asks for an email address followed by a
I have this observer that watches the UISwitch for a change in value: [cell.switcher

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.