Passing and Reading URL Parameters

Many developers have a set of wrong ideas about Rails parameters. See how you can deal with them in real life. Read on and learn more.

Introduction



"Ruby on Rails" (RoR) has always been quite handy as far as passing and reading URL parameters are concerned. However, there is a common perception that the URL parameters get passed as a simple string. This article discusses the RoR representation of URL parameters and how users can use this information to parse and use URL parameters effectively and efficiently.



Rails and URL Parameters



First, you need to learn about parameter passing in Rails with an example. Listing 1 shows a URL with a set of parameters being sent to the recipient server that has been hosted on the local machine.

Listing 1.




http://localhost/users/create?user[first_name]=dhanabal&user
[last_name]=arumugam&arr []=1&arr []=7&arr []=3&id=15


As the users of Rails may already be aware, "users" stands for the controller class "UsersController" and "create" is the method within the "UserController" class.




"user[first_name]=dhanabal&user[last_name]=arumugam&arr
[]=1&arr []=7&arr []=3&id=15"


are the parameters to the method "create".

Typically, the URL parameters are sent as a set of simple name value pairs, as in the example "name=tom&age=21". In the Rails convention, also, parameters are sent as a set of name value pairs. However, there is a slight difference. Rails eases parameter passing and makes the object relational mapping by qualifying the parameters with the model object and the model attributes. In the example above, the term "user" maps to the model (table) user and "first_name" maps to the attribute "first_name" of the model class (column first_name of the table user).



Arrays



Read the Rest of this Article at Developer.com

Related Articles
- So, You Want Info On... CSS and Backgrounds, Huh?
Colors, images, full and partial page backgrounds, background-repeat, and the watermark - all here!
- Working with the TextStream Object
- Creating RSS Feeds
- Headline Script
- The Case for Components
Regional Articles
- Passing and Reading URL Parameters Alabama
- Passing and Reading URL Parameters Alaska
- Passing and Reading URL Parameters Arizona
- Passing and Reading URL Parameters Arkansas
- Passing and Reading URL Parameters California
- Passing and Reading URL Parameters Colorado
- Passing and Reading URL Parameters Connecticut
- Passing and Reading URL Parameters DC
- Passing and Reading URL Parameters Delaware
- Passing and Reading URL Parameters Florida
- Passing and Reading URL Parameters Georgia
- Passing and Reading URL Parameters Hawaii
- Passing and Reading URL Parameters Idaho
- Passing and Reading URL Parameters Illinois
- Passing and Reading URL Parameters Indiana
- Passing and Reading URL Parameters Iowa
- Passing and Reading URL Parameters Kansas
- Passing and Reading URL Parameters Kentucky
- Passing and Reading URL Parameters Louisiana
- Passing and Reading URL Parameters Maine
- Passing and Reading URL Parameters Maryland
- Passing and Reading URL Parameters Massachusetts
- Passing and Reading URL Parameters Michigan
- Passing and Reading URL Parameters Minnesota
- Passing and Reading URL Parameters Mississippi
- Passing and Reading URL Parameters Missouri
- Passing and Reading URL Parameters Montana
- Passing and Reading URL Parameters Nebraska
- Passing and Reading URL Parameters Nevada
- Passing and Reading URL Parameters New Hampshire
- Passing and Reading URL Parameters New Jersey
- Passing and Reading URL Parameters New Mexico
- Passing and Reading URL Parameters New York
- Passing and Reading URL Parameters North Carolina
- Passing and Reading URL Parameters North Dakota
- Passing and Reading URL Parameters Ohio
- Passing and Reading URL Parameters Oklahoma
- Passing and Reading URL Parameters Oregon
- Passing and Reading URL Parameters Pennsylvania
- Passing and Reading URL Parameters Rhode Island
- Passing and Reading URL Parameters South Carolina
- Passing and Reading URL Parameters South Dakota
- Passing and Reading URL Parameters Tennessee
- Passing and Reading URL Parameters Texas
- Passing and Reading URL Parameters Utah
- Passing and Reading URL Parameters Vermont
- Passing and Reading URL Parameters Virginia
- Passing and Reading URL Parameters Washington
- Passing and Reading URL Parameters West Virginia
- Passing and Reading URL Parameters Wisconsin
- Passing and Reading URL Parameters Wyoming

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML