views:

656

answers:

11

What specific piece of advice could have saved you from going down the wrong track, saved you lots of rework or just helped you generally?

+4  A: 

Models don't need to extend ActiveRecord (represent a database table) - they can just be for some form data or a non-persisted class used by your controller.

RichH
+19  A: 

Don't use scaffolding.

Sarah Mei
+1 scaffolding had me believing that rails was written to generate blog post with comments. Don't do use them. Learn MVC on your own. It will open your eyes.
basszero
+9  A: 

Don't name attributes 'type'.

_Kevin
I still catch myself doing that every once in a while.
Jarrod
I got burned by that one too.
Mike Reedell
This is a good one. Actually method name collisions are one of the few places where the static typing camp are right. I've run into very confusing bugs in apps that use an attribute that is the same as a method on Kernel or Object, for example: binding.
Jason Watkins
+3  A: 

Kept me from going down the wrong track: Namespaces in Rails aren't worth the hassle.

Saved lots of rework: You can write your own generators.

Just helped generally: rake db:fixtures:load

Bonus tip (not Rails specific): Learn version control. Even if you're coding alone.

Edit: Loading fixtures into the dev database still seems wrong. Suggestions are welcome.

Jarrod
there's now a specific feature for loading bootstrap data in the latest rails.Also, fixtures suck. Sadly you don't learn this until you get a project big and complicated enough that you start seeing ripple test failures from fixture changes. Inline setup where each test stays independent ends up being much more maintainable.
Jason Watkins
I saw seed.rb too. Looking forward to it.
Jarrod
+19  A: 

The main one for the first days? Don't Panic. The rails api is larger than people really advertise. It will take a while for you to memorize the portions that you use on a daily basis. Parts of it won't make sense until you use it for a bit. This applies doubly so if you're coming from a c/pascal/algol style language and using a language like Ruby for the first time.

Here's a grab bag of other ones:

And then there's my standard list for development as a whole:

There's no silver bullet to hacking rails, or otherwise, but I believe considering the above will save most people enormous amounts of pain. It's a sad commentary on our profession that so many wander lost in the hinterlands attempting to wrangle piles of spaghetti code via their clipboard hoping that it'll all just work in time for the deadline.

Jason Watkins
Those api docs are much better. Just to add to that, I wish http://guides.rubyonrails.org/ had been around when I started.
Jarrod
+3  A: 

Learn by actual information.

Rails changes very quickly and you will get a lot of troubles if you will use information related to the old Rails version while you have modern version on your computer. If you are reading post in blog take a look at it publish date. If you are reading book then read about Rails version it is uses in examples.

IDBD
+10  A: 

Learn Ruby First.

Rails is, unfortunately, not magic - most of the good stuff in the framework comes from the power and expressiveness of the Ruby language itself. You need to have a solid grounding in Ruby to get the most out of it, including Ruby metaprogramming techniques for when you (inevitably) have to dig into some of the Rails source code to understand/fix something.

I'd highly recommend the Manning book 'The Well Grounded Rubyist" for a good overview of the language (http://www.manning.com/black2/)

David Burrows
I think that's analogous to saying you should learn how a car works before learning how to drive. Sure, it helps and makes you a better driver, but its not a prerequisite, and you can manage just fine diving right in and learning the details of what's under the hood as you progress, or as you need to.
Teflon Ted
The analogy is good if you take into account the maturity of the automobile v Rails. When cars were only 5 years out of the lab it was probably a really good idea to know what was going on mechanically so you could fix any glitches without professional help. If Rails was over 100 years old then you probably could just dive in without too much trouble but, although it's a solid solution, Rails is in flux. Learning Ruby will stop you spending long hours sat at the side of the road, waiting for the metaphorical tow truck to arrive.
David Burrows
+4  A: 

Take a good look at the Hash and Array classes and understand what they can do - so many of the data manipulations you'll need are really easy ... once you know how.

RichH
+6  A: 

Make sure you've got a plan for how you are going to host your project. Good Rails hosts aren't as easy to find as PHP hosts.

http://stackoverflow.com/questions/251418/who-are-good-web-hosts-for-ruby-on-rails-projects

RichH
+2  A: 

I've made several attempts at learning RoR. First (and unsuccessful) attempts I've looked from top, installing instant Rails, generating scaffolding, learning by reading. I had lots of experience programming in C++, Java, and C# and I thought that just some scripting language doesn't need to be learned.

And I was wrong. Everything really seemed like magic, I had no idea what the fuck was going on. Only after several attempts, separated by several years, I've finally started understanding Rails.

The way I did was not to look at a finished Rails scaffolding but start from basics and break stuff. I would start from the Ruby itself, not even thinking about Rails, breaking everything to understand how it works. Then I'd pull some gems, including ActiveRecord to learn how ORM works. Then I learned about views. I really broke everything apart and learned about it individually a long time before I finally typed in "rails test_project" and started understanding MVC and how all the components worked together.

What would I advice: break everything. In both meanings: break so it doesn't work (and understand why) and break into small parts to ease understanding.

mannicken
+2  A: 
  • Be sure you're already confident working with databases, (rails models will burn you if you don't have a good understanding of SQL)

  • Watch out for RJS: it's a ruby programming model for manipulating a page with AJAX. It may really help you, but if you're not also aware of pure javascript frameworks like jQuery you may find your productivity drops when you try to make highly dynamic sites.

  • There's a rails plugin for almost everything.

  • Most plugins are hosted on git. If you're using something else, (like SVN), get an IDE like RubyMine which will happily let you use git-hosted plugins while your project is hosted in a different version control system.

Lee