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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:09:25+00:00 2026-05-31T01:09:25+00:00

On my view, I have 2 URLs I need to create. Each has a

  • 0

On my view, I have 2 URLs I need to create. Each has a separate value for sort but must include all previous settings for ratings.

In order to create this URL, on the controller, as the last step, I muck with the params hash:

params.delete :controller
params.delete :action
params.delete :commit
params.delete :utf8

params[:ratings] = @ratings

@titleparams = params
@dateparams = params

@dateparams[:sort] = "release_date" 
@titleparams[:sort] = "title"

I expect @titleparams and @dateparams to be separate copies of params. Then I add the sort param to each.

The view displays them with the same code but in different THs as:

%a#release_date_header= link_to "Release Date", movies_path(@dateparams)

%a#title_header= link_to "Movie Title", movies_path(@titleparams)

I also have a section at the top of the page to see what @dateparams and @titleparams are coming page to view as. They are the same and I don’t understand why.

%hr
=@titleparams
%hr
=@dateparams
%hr

Displays as (ignoring hr for this post)

{"ratings"=>{"G"=>"1", "PG"=>"1"}, "sort"=>"title"} 
{"ratings"=>{"G"=>"1", "PG"=>"1"}, "sort"=>"title"} 

It seems the last sort to be added is the keeper. I.e., the title was the last sort added in the code of the controller’s action so it is the last in the two different params lists.

I don’t understand why the params copy into the two different variables is acting like pass by reference instead of pass by value. I’m new to Ruby but I haven’t seen this before in my Ruby work.

  • 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-31T01:09:26+00:00Added an answer on May 31, 2026 at 1:09 am

    When you assign a has to another variable in Ruby, you assign the reference, not a copy of the hash. So @titleparams and @dateparams both reference the same underlying Hash as params itself. It’s clear, then that, you set :sort to "release_date" and then overwrite with "title".

    Try dup to get an actual copy:

    @titleparams = params.dup
    @dateparams = params.dup
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Pages table that stores all my view urls and this table
I'm doing a project in seam that requires restful URLs. I have a view
i have view like 'home/details/5', it can be access by anonymous user. but there
In a certain view I have got different elements and I need the keyboard
I have a list of urls in a grid, And I need that when
I have some YouTube URLs stored in a database that I need to rewrite.
It's easier to be told by example. I have URLs like http://domain/product/view/id/ . How
I have view controller, into the view i have put a table view, and
I have an ASP MVC view where have the following statement #if DEBUG //section
In my View I have a slider and a combobox . When I change

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.