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 6777725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:10:55+00:00 2026-05-26T16:10:55+00:00

content = Content.find(params[:content_id]) content.body.insert(start_index, span_open) content.save! content.body.insert(end_index + span_open.length, span_open) content.save! puts ========================================== c

  • 0
content = Content.find(params[:content_id])
content.body.insert(start_index, span_open)
content.save!
content.body.insert(end_index + span_open.length, span_open)
content.save!

puts "=========================================="
c = Content.find(params[:content_id])
puts c.body

so the above is what I’ve been trying to do. lots of saves.. it should save right?

in the console I see

===========================================
le modified text (body attr) here

I’m inserting span’s into text, and in the console (above) it shows the changes successful in the puts statement. But when I rerender the page, everything is back the way it was (inspect element shows no spans)

One thing that I find weird is that the puts statement executes before the

"Processing NameOfController#action (for ....)" 

with all the DB calls and such. I scroll down to where Content.find would be (it’s there twice, so this is easy) and I see this:

SHOW FIELDS FROM `contents`
  Content Load (1.6ms)   SELECT * FROM `contents` WHERE (`contents`.`id` = 328) 
  SQL (0.2ms)   BEGIN
  SQL (0.1ms)   COMMIT
  SQL (0.1ms)   BEGIN
  SQL (0.2ms)   COMMIT
  CACHE (0.0ms)   SELECT * FROM `contents` WHERE (`contents`.`id` = 328) 
  SQL (0.1ms)   BEGIN
  SQL (0.1ms)   COMMIT

Now, it says that it’s loading the second call from cache… what’s up with that? since I’ve changed it since the last .find()?

I’m using Ruby on Rails 2.3.8

UPDATE: incorporating Dan Seaver’s suggestions:

  content = Content.uncached_find(params[:content_id])
  content.body = content.body.insert(start_index, span_open)
  content.save!
  content.body = content.body.insert(end_index + span_open.length, span_close)
  content.save!
  a = content.body
# ActiveRecord::Base.connection.update("
#      UPDATE `contents`
#      SET body = '#{content.body}'
#      WHERE id = #{params[:content_id]}")
puts "=========================================="
content = Content.uncached_find(params[:content_id])
  puts (a == content.body).inspect

output / terminal:

==========================================
false

Content Load (1.5ms)   SELECT * FROM `contents` WHERE (`contents`.`id` = 351) 
  SQL (0.1ms)   BEGIN
  SQL (0.1ms)   COMMIT
  SQL (0.1ms)   BEGIN
  SQL (0.2ms)   COMMIT
  Content Load (0.3ms)   SELECT * FROM `contents` WHERE (`contents`.`id` = 351) 
  • 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-26T16:10:56+00:00Added an answer on May 26, 2026 at 4:10 pm

    The way that Rails SQL Caching works is that queries are cached within an action:

    However, it’s important to note that query caches are created at the start of an action and destroyed at the end of that action and thus persist only for the duration of the action. If you’d like to store query results in a more persistent fashion, you can in Rails by using low level caching.

    This article describes how you can avoid the cache with the following

    Update Not having previously used uncached, it seems like is defined within active record, so you will have to add a class method to content like the following:

    def self.uncached_find(content_id)
      uncached do 
        find(content_id)
      end 
    end
    

    Then use Content.uncached_find(params[:content_id]) (documentation) where you would use Content.find

    Update 2 I see the issue now!! You aren’t actually modifying anything. String#insert returns a modified string, it does not modify content.body in place, you need to do the following:

    content.body = content.body.insert(start_index, span_open)
    

    Try the above line with your save, and it should work

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

Sidebar

Related Questions

Where could I find out the content type for a specific file format/extension? For
In MOSS2007 I need to find and remove for example the default content type
I'm looking for a way to find/replace links to images (within user-generated content) without
I am trying to examine the contents of an assembly and find all classes
Hi I'm using the rails plugin acts-as-taggable-on and I'm trying to find the top
So, I've been trying to set up a before_filter for checking permissions for whether
I've been trying to implement a commenting system for my Rails app. Every event
mime_content_type() is deprecated. How can I find the MIME type of a local file
I got an hotfix from microsoft (msu file). How can i find the contents
i'm using preg_match_all('/<?(.*)?>/', $bigString, $matches, PREG_OFFSET_CAPTURE); to find the contents of everything between <?

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.