Topic: Things You Shouldn't Be Doing in Rails

I just read an interesting article on things which you should avoid doing in Rails. There are some points I'm a little uncertain about, but most of them I agree with. It's worth checking out either way:

Guide: Things You Shouldn't Be Doing In Rails

Railscasts - Free Ruby on Rails Screencasts

Re: Things You Shouldn't Be Doing in Rails

I just read this too, good article.  I agree that Rails' pagination helper kinda sucks, but I think he should have cited some kind of alternative.

Re: Things You Shouldn't Be Doing in Rails

Hmmmm... some interesting points. Seems like some of it is a matter of point-of-view, though. I mean, granted, the pagination might break with millions of rows, but is that really a reason to stop using it full-stop?.. It's still useful and still has it's place.

Perhaps I'm just naive, or it's the fact that it's not very well explained as why not to use them, but I don't see what's wrong with components. Same goes for Controllers in namespaces - rather than say "don't use them" I think the point should be "be very careful with controller/model naming if you're going to use them".

Re: Things You Shouldn't Be Doing in Rails

I think the problem with components is that they create an entirely separate request to grab the content.  This is just a waste of resources.

But yeah, there's not a lot of explantion for these no nos.  Basically he just saying "trust me, you dont wanna do this".

Re: Things You Shouldn't Be Doing in Rails

I agree, the article should have contained better explanations on why not to do something and alternatives. But, if you can avoid doing the things on the list, I would. It appears alternatives are being mentioned in the comments as well.

Railscasts - Free Ruby on Rails Screencasts

Re: Things You Shouldn't Be Doing in Rails

Personally I find the article rather poor; even more so for what it seems to be revealing about attitudes on -core.  Issues like Rails built-in pagination is broken or confusing interactions in name-spaced controllers should lead to improvements to the Rails source, not in removing (buggy) functionality to a plugin or discouraging some useful design options.

Namespaced controllers I've found to be extremely useful, but in need of significant work to make truely integrated with the framework.  However I suspect even if someone put the time in to make a patch, core would just drop it as its not part of the kool-aid....

My RoR journey  -- thoughts on learning RoR and lessons learned in applying TDD and agile practices.

Re: Things You Shouldn't Be Doing in Rails

I don't have a problem with pagination or namespaced controllers. Actually I've always found it pretty cool that database-agnostic pagination was as easy as it is in Rails, even if it doesn't scale to thousands/millions of records.

vinnie - rails forum admin

Re: Things You Shouldn't Be Doing in Rails

<rant>

You have to be kidding? Someone is worried about pagination not scaling up to millions of records. Ummmm, did anyone stop to think about the repetitive stress issues surrounding paging through millions of records?

Sorry, but if that's the definition of a weak point in Rails, I suggest anyone who would contemplate using pagination on a dataset that large look at his or her information presentation skills.

</rant>

Re: Things You Shouldn't Be Doing in Rails

cwd wrote:

Sorry, but if that's the definition of a weak point in Rails, I suggest anyone who would contemplate using pagination on a dataset that large look at his or her information presentation skills.

LOL Amen.

Any time you have to page through millions of records (heck, more than a few hundred) then that's a sign of some sort of serious design flaw.

Re: Things You Shouldn't Be Doing in Rails

*cough* Amazon's Ecommerce Services *cough* wink

Josh Catone helps run this place
Rails Forum - Rails Jobs

Re: Things You Shouldn't Be Doing in Rails

Edit: I am an idiot. Thank you, that is all (also, I agree, Josh).

Re: Things You Shouldn't Be Doing in Rails

sometimes I feel like such an moron when reading these boards but here goes... what's the issue here? surely kelli's orginal point *is* correct, if we're trying to display anything over a few hundred records we've frigged ourselves in terms of UI somewhere, haven't we?? yikes

ok leaving aside google, amazon et al - but rather for us mere mortal web programmers, when the hell is anyone displaying that number of records?? Surely common sense dictates that we introduce some kind of prior selection to the records before showing hundreds/thousands?

Or am I missing the *entire* gist of this conversation? (which wouldn't be the first time!) - answers on a postcard to the moron in the corner :0)

Last edited by Baltar (2006-09-04 10:08:51)

Re: Things You Shouldn't Be Doing in Rails

True, on the user-interface side it is important to cut down on the number of records shown through some kind of filtering. But, we also need to allow for the possibility that all the records - or nearly all of them - can be displayed. For example, if someone does a text search and chooses a common word that is in nearly all of the records, we don't want our Rails app to slow down to a crawl trying to handle the pagination. We don't want the app to be that fragile so performance testing is necessary - even if it goes beyond the bounds of the everyday use. I don't mean by this that no one should use the provided Paginator, I just encourage you to do some performance testing to see if it will be a problem.

On the other hand, this isn't the only problem with pagination in Rails. The helper methods are rather inflexible and every time I use them I feel there is a better way. I haven't come up with a better way though, so I probably shouldn't complain.

If you are asking yourself wether to use the rails provided pagination helpers or role your own, I say do the simplest thing that could possibly work. For now that would mean use the pagination helper methods. They are so easy to use and use so little code, you really don't lose anything if they don't work for you. Once you start investing into something - say rolling your own pagination with 100 lines of code, then you need to be careful and have a very good reason to do so.

Railscasts - Free Ruby on Rails Screencasts

14

Re: Things You Shouldn't Be Doing in Rails

I'm not getting the gist of this argument. Any code construct that indiscriminately grabs an unbounded set of records is suspect practice. This has nothing to do with pagination; rather, it has to do with not setting an upper limit on the retrieval. There's a plugin that addresses some of these issues:

http://cardboardrocket.com/

However, whether you are doing pagination or simply turning an unbounded find() loose on an unknown size database, you're asking for trouble.

No?

Re: Things You Shouldn't Be Doing in Rails

I gotta agree with cwd here - I reckon a well designed app should throw up an interference screen saying something like, your search returned too many results, trying adding additional terms - in the end you're saving your user a lot of wasted time because users being users if you give them the option they'll spend five minutes clicking through endless screens till they reach page 376 of the record 't' - better that they specific earlier what it is they're looking for, and save themselves, and your database the trouble.

Yeah I know there are going to be the odd exceptional cas that breaks this rule, but I think for the *vast* majority of situation just doing a 'mass-dump' of the database to a paginated page display is pretty shady for all involved. Perhaps there was more argument for it pre-Rails, but with all the time saved by rails magic I reckon a better search system and retrival system is the way forward.

just my 2 cents, and hey I ain't exactly practicing what I preach here, some of my past sites have done some *truly horrible* things in these situations ;0D

Re: Things You Shouldn't Be Doing in Rails

Baltar wrote:

I gotta agree with cwd here - I reckon a well designed app should throw up an interference screen saying something like, your search returned too many results, trying adding additional terms - in the end you're saving your user a lot of wasted time because users being users if you give them the option they'll spend five minutes clicking through endless screens till they reach page 376 of the record 't' - better that they specific earlier what it is they're looking for, and save themselves, and your database the trouble.

I think it depends largely on what is being searched. I wouldn't want Google to prevent me from searching for "ruby on rails" because it turns up 36 million hits.

Railscasts - Free Ruby on Rails Screencasts

17

Re: Things You Shouldn't Be Doing in Rails

I'm skeptical that Google reads 36 million rows into memory to tell you that...

Re: Things You Shouldn't Be Doing in Rails

Oh, we are talking about two different things here: user experience and performance. I was referring to how Google handles the user-experience side of things. The user doesn't care wether google loads all 36 million rows into memory or not (just as long as it's fast enough). If it's not fast enough, then I would first try to optimize it without making the user experience suffer.

Last edited by ryanb (2006-09-04 16:08:06)

Railscasts - Free Ruby on Rails Screencasts

Re: Things You Shouldn't Be Doing in Rails

ryanb - yeah I agree with you that apps like search engines etc you don't want to pre-limit your users too much, that's what I meant with the 'us mere mortals' comment in my first post - for *our* likely kind of data I think it probably best to try and define the terms of the search more before showing the data. For example, take say an ecommerce app, or forum software, where the admin (or maybe even the users) can view a huge list of all the memebers/customers; personally speaking I don't really see the benefit in being able to browse a huge list of all the records, for me personally, in the future I think I'll spend my time making a decent 'record selection' page that allows for much more pre-selection. But I suppose you're right, at the end of the day it all comes down to the individual case. Interesting discussion this one, always disliked those huge member/customer lists you get in medium sized apps, never really spent the time before to figure out what to do about it though :0)

now i suppose just need to find some projects big enough that any of this stuff starts to become an issue for me!

Re: Things You Shouldn't Be Doing in Rails

I just saw this blog post/tutorial that was inspired by the Things You Shouldn't Be Doing article: http://www.igvita.com/blog/2006/09/10/f … -in-rails/

It's about how to acheive faster pagination in Rails.  It seems pretty slick and I thought it might interest people who took part in this discussion. smile

Josh Catone helps run this place
Rails Forum - Rails Jobs