The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
SUP

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Amos King

Posts: 78
Nickname: adkron
Registered: Jan, 2007

Amos King is a Web Developer for the US Postal Service and for Ramped Media.
SUP Posted: Feb 22, 2009 9:37 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Amos King.
Original Post: SUP
Feed Title: DirtyInformation
Feed URL: http://feeds.feedburner.com/Dirtyinformation
Feed Description: Information about Ruby/Rails/JRuby/WebDevelpoment/whatever.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Amos King
Latest Posts From DirtyInformation

Advertisement

Stop URL Parameters(SUP)

Any time I see a ?foo=bar in a url I get so frustrated. I'm especially irritated when it the parameters came from a form. Let's stop this horrible practice. If you need parameters great, but pass them with a post or as part of the regular url.

I've seen this happening at an increasing rate. It usually comes with someone trying to follow RESTful principles with their code, but becoming confused along the way. Here is an example:

  • I have a few reports that I want to display based on some dates
  • ...I know...that is a "show" method since I'm "showing" data to the user
  • Now I need the report to be based on a date range.
  • I also need a select box for the report type to be chosen.
  • I'll make a form that posts to this action here, and then it will redirect to the correct report.
  • hmm...How am I going to pass those dates along...Eureka! I'll just put ?start_date=foo&end_date=bar on my URL

Now is the time to say STOP! Why do you want to do this. Sit back, and rethink your actions. Starting down the path of just tossing the parameters into the url can lead to many problems. It is like a gateway drug. It seems so easy and useful the first time, and now you've got secure data in the url, and a horrible API, and we won't even talk about error handling and the back-end code that is making this up. Now that your boss is angry that you passed an SSN in the url you would like to go back and fix this issue once and for all.

It is OK to display data with a create or update. If you have a mental block on this think of it as creating the report. Then instead of having a new controller for each report, and a show action for each have the create action render a specific template based on the report selected. The partial can even be the name of the report, then you don't need an if/case block. Now you've got one small method that is handling all the reports. If they are complicated create some models for the reports, and your set.

I've been wanting to get that off my chest.

Read: SUP

Topic: Interview: Chris Wanstrath of GitHub Previous Topic   Next Topic Topic: Useful unix tricks - part 3

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use