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.
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.