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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:00:51+00:00 2026-06-12T20:00:51+00:00

My URL is as follows: http://localhost:3000/movies?ratings[PG-13]=1&commit=Refresh I’m experimenting evaluating URL params and am unsure

  • 0

My URL is as follows:

http://localhost:3000/movies?ratings[PG-13]=1&commit=Refresh

I’m experimenting evaluating URL params and am unsure why this works the way is does. In my controller I evaluate the parameters and build an array as follows:

In my View I use the following debug statement to see what gets placed into @selected_ratings

=debug(@selected_ratings)

In my controller I have tried two statements.

Test one returns the following, this should work?

@selected_ratings = (params["ratings[PG-13]"].present? ? params["ratings[PG-13]"] : "notworking")

output: notworking

However if I use the following ternary evaluation n my controller:

@selected_ratings = (params["ratings"].present? ? params["ratings"] : "notworking")

output:!map:ActiveSupport::HashWithIndifferentAccess 
  PG-13: "1"

Why will my evaluation not find the literal params["ratings[PG-13]"]?

  • 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-12T20:00:52+00:00Added an answer on June 12, 2026 at 8:00 pm

    Rails parses string parameters of the form a[b]=c as a hash [1] where b is a key and c is its associated value: { :a => { :b => "c" } }.

    So the url http://localhost:3000/movies?ratings[PG-13]=1&commit=Refresh will result in the hash:

    { :ratings => { :'PG-13' => "1"}, :commit => "Refresh" }
    

    In your first assignment, you check if params["ratings[PG-13]"] is present, and since it is not, it returns “notworking”. In the second case, you check if params["ratings"] is present, and it is, so it returns params["ratings"], which is a hash with the key PG-13 and value "1".

    [1] Or rather, a HashWithIndifferentAccess, a special kind of hash that converts symbol and string keys into a single type.

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

Sidebar

Related Questions

I have a url as string in javascript like follows : http://localhost:8080/Blah.ff?param=1&param=2 ... I
I am passing query string and the url is as follows-> http://localhost:1086/Web/EditMobile.aspx?sno=2 . But
I have a configuration setting in web. config file as follows: <param name=url value=http://localhost/services.msc>
If you have a url such as the one as follows: http://www.example.com/400x200 is it
I try to get this following url using the downloadURL function as follows: http://www.ncbi.nlm.nih.gov/nuccore/27884304
Suppose I am retrieving a url as follows: string url = http://www.somesite.com/somepage.html HttpWebRequest req
When I attempt to use SWI-Prolog's http_post/4 , as follows: :- use_module(library(http/http_client). update(URL, Arg)
A web browser is calling my action with the following URL; Request URL:http://localhost:4000/MyController/UrlCheck?Menu.Url=sometext My
I have the code for the following url:http://localhost/summary/myfile.csv I want the url to look
I am trying to use relative url with a post ajax call as follows:

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.