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

  • SEARCH
  • Home
  • 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 7045243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:30:26+00:00 2026-05-28T02:30:26+00:00

Rails: object = Object.find_by(params[:id]) object_items = { 1 => { :id => 123456, :name

  • 0

Rails:

object = Object.find_by(params[:id])

object_items = { "1" => { :id => "123456", :name => "Pancakes Yum!" }, "2" => { :id => "789010", :name => "hello 123" }}

cookies[:something] = { "id" => object.id, "title" => object.title, "object_items" => object_items }.to_json

Let’s say that object.title produces a string “Hello World”

Cookie Content:

%7B%22id%22%3A2%2C%22title%22%3A%22Hello+World%22%2C%22object_items%22%3A%7B%221%22%3A%7B%22id%22%3A%22123456%22%2C%22name%22%3A%22Pancakes+Yum!%22%7D%2C%222%22%3A%7B%22id%22%3A%22789010%22%2C%22name%22%3A%22hello+123%22%7D%7D%7D

Problem:

The JSON string being created replaces/escapes whitespace with a plus sign (+) instead of %20 which means that if I were to read the string and grab the value for object.title in HTML/JavaScript it will read it as “Hello+World” and not “Hello World” as expected.

All other characters seem to be replaced/escaped properly – is it because the space exists inside a double quote? I can’t figure out why it’s producing this string as it is.

  • 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-05-28T02:30:26+00:00Added an answer on May 28, 2026 at 2:30 am

    I don’t understand why you are communicating with the client via cookies. Why not use a controller action and ajax request?

    class SomethingController
      def show
        object = Object.find_by(params[:id])
    
        object_items = { "1" => { :id => "123456", :name => "Pancakes Yum!" }, "2" => { :id => "789010", :name => "hello 123" }}
    
        render :json => { "id" => object.id, "title" => object.title, "object_items" => object_items }
      end
    

    Then request it using jQuery or something like this:

    $.get('/something/1.json', function(results) { alert(results); });
    

    What’s the point in using Rails if you’re not going to use Rails?

    Cookies are CGI escaped before being sent to the client. When the client retransmits them Rails unescapes them.

    You can test the behaviour like this:

    rails console c
    CGI.escape("something something")
    => "something+something"
    CGI.unescape("something+something")
    => "something something"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails template (.rhtml file) generating a Javascript object. It looks something
We have a Rails app that instantiates a SWF object 16 times (it has
Does anyone know of any method in Rails by which an associated object may
Possible Duplicate: Rails primary key and object id Very quick question. My server is
In Ruby on Rails, say a Story object can has_many Vote objects (a story
I'm trying to do this: def assert_record_not_found(method, object, action, params) begin method action, params
I've hit something that I don't understand how to model with Rails associations and
i have two question 1.How do i stub a nil object in rails test
Where does Rails store data created by saving activerecord objects during tests? I thought
In my rails app I use the validation helpers in my active record objects

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.