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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:56:17+00:00 2026-05-24T12:56:17+00:00

This is driving me crazy… Here’s what I THINK I’m doing in the #show

  • 0

This is driving me crazy… Here’s what I THINK I’m doing in the #show action of my users_controller.rb

  1. I’m setting session[:zot] ONLY via the method “pass_session_data()”.
  2. In that method, I pass the contents of “@foo” to the session[:zot].
  3. Later in the #show action, I call amz_search(), and I replace some text in @nowreading.content with the a URL and that text.

After the calling the method “amz_search()” all bets are off. When I put “test 4”, I see the session[:zot] changed to include the URL that I added to @nowreading.content. Worse still, my variable @foo also changed when I changed @nowreading.content. WTF. I don’t understand how these two variables are linked!

What am I doing wrong? I want to pass the unaltered text (@foo before it changes to the version with the URL) to session[:zot].

In the show action of the Users controller, I have:

@user = User.find(params[:id])
@nowpost = Nowpost.new

@tweet_sample = Micropost.find(:all, :conditions => ["username = ?", "#{@user.twithandle}"])

@multi_streams = (@tweet_sample + @user.nowposts).sort_by(&:updated_at)
# takes all posts in the systems and order them by update-time

parse_the_streams(@multi_streams) 

pass_session_data() 

 puts "test 3"
 puts session[:zot]
 puts "this is @foo = #{@foo.content}"
 puts "Test C = #{@nowreading_raw.content}"   

amz_search(@reading_title, 'Books')

 puts "test 4"
 puts session[:zot]
 puts "this is @foo = #{@foo.content}"
 # @foo totally changed even though I only updated @nowpost.content
 # I don't understand how these two variables are linked!
 puts "Test D = #{@nowreading_raw.content}"   

 end #show action

Here are the methods call from the show action:

 def parse_the_streams(multi_streams)
     multi_streams.each do |tweet, i|  
 puts "i = #{i} // tweet = #{tweet.content}"
       if tweet.content.match(/#nowreading/).to_s == "#nowreading"    
         @nowreading_raw = tweet 
         @foo = tweet
         tweet.update_attributes(:cat_id => "1")

        if tweet.content.match(/#nowreading$/)
          @reading_title = tweet.content.match(/([^\s]*\s){5}(#nowreading$)/).to_s
        else
          @reading_title = tweet.content.match(/'(.+)'|"(.+)"/).to_s
        end              
     end
   end
 end

 def pass_session_data  
      @nowreading = @nowreading_raw
      puts "PASS SESSION DATA"
      puts "this is @foo = #{@foo.content}"
      puts "----------"
      reading = @foo

      content = {
      "reading"=>reading
      }

      session[:zot] = content
    end

  def amz_search(search, index)
        res = Amazon::Ecs.item_search(search, {:response_group => 'Images', :search_index => index})
        puts "Test 1 = #{session[:zot]["reading"].content}" 

        tempy = @nowreading.content.match(/#nowreading.*/).to_s.gsub("#nowreading",'') # strips away the #nowreading tag

        puts "Test 2 = #{session[:zot]["reading"].content} -- this is still OK"   
        puts "and FOO hasn't changed yet = #{@foo.content}"   

        url = create_amz_url(search, asin)["finished"]

        @nowreading.content = tempy.match(/#{search}.*/).to_s.gsub("#{search}", url)

        puts "WTF -- @foo changed -- WHY!?!? = #{@foo.content}"   
        puts "Test 4 = #{session[:zot]["reading"].content}"
  end

  def create_amz_url(text, asin)
     url = Hash.new
     url["raw"] = "http://www.amazon.com/dp/#{asin}/#{associate_code}"
     link = "http://www.amazon.com/dp/#{asin}/#{associate_code}"
     url["finished"] = "<a href=#{link} target=\"_blank\">#{text}</a>"
     return url
  end

Thank you for your help.

  • 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-24T12:56:18+00:00Added an answer on May 24, 2026 at 12:56 pm

    You should spend 30 minutes refactoring that code – eliminate as many instance variables as possible and use explicit arguments to your functions rather than operating on the instance variables.

    I’m pretty sure your problem is that

    @foo == @nowreading == @nowreading_raw
    session[:zot] = {"reading" => @foo}

    and then you change @nowreading right before your WTF statement.

    tweet is an object, so when you say @foo=tweet; @nowreading=tweet, @foo and @nowreading point to the same object, and modifying either will modify both.

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

Sidebar

Related Questions

this is driving me crazy. I think my website is infected by some sort
This is driving me crazy! I have read at least 5 questions on here
This is driving me crazy already and by now I'm absolutely hopeless :( Here
This is driving me crazy. I want to show in a QWebPage an url,
I'm sure I'm doing something silly, but this is driving me crazy. I'm trying
This is driving me crazy. Can anyone tell me what I am missing here.
This is driving me crazy and most likely I am doing this wrong. So
This is driving me crazy. I am creating a splitview app on iPad. I
This is driving me crazy... With this simple code I keep getting file not
This is driving me crazy. I have a PHP script that gets some data

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.