26 points · by NathanKP · 16y ago · 19 comments
The basics of the ruby language have been easy enough to master. It is just slightly different syntax and grammar. However, I have so far found it impossible to get started with Rails.
I have heard all the statements like "development in Ruby is 10x faster than development in PHP" but so far it is proving 10x harder to learn and 10x less documented.
Readjusting my thinking to work with the MVC framework is proving difficult, and its not helping that most of the tutorials I find are old or contain bugs that cause them to not work.
I find a nice looking tutorial, follow it perfectly and it fails because routes are not being set properly. Or I try to use gems such as restful authentication and they cause the server to fail on startup.
Ruby on Rails seems nice and I'm sure that once I get experienced with it I'll enjoy the 10x faster development speed, but so far it has proved 10x more frustrating to learn than PHP.
Do you have any tips or advice on learning Rails? Do you know of any decent (working) tutorials for learning MVC thinking?
It's probably not the best way to learn Ruby, but the most fun way is definitely reading _why's poignant guide[1]. It's awesome and teaches you pretty well (you can find PDFs and such out there too).
Once you're satisfied with your command of Ruby:
I'm not really sure what the best way to get started is. I think RailsGuides[2] is supposed to be pretty good. The "getting started" page looks good and complete. When I started, the first thing I did is read the very-introductory parts of the Pragmatic Programmers' book[3], which is great. I didn't bother with the whole thing, just got the basics from it and then learned by doing, occasionally referring to it.
Once I read a few chapters of the pragprog book, I looked at official rails docs (I think it was guides.rubyonrails.org, but that site has evolved a lot since then), got started with something pretty simple, and googled if I had any trouble. For specific issues like getting exceptions, the api documentation[4] can be pretty useful. Though really, you should use apidock.com/rails because it's way more searchable (it's the same docs, plus some comments that apidock users have added, they just made a better search and made it less ugly).
Also, if Rails isn't doing it for you (especially if you do love Ruby), take a look at Sinatra and Padrino. There's of course way more plugins out there for Rails, but you can still use any gems (libraries), and it can be less annoying than Rails.
I'm not sure of any good ways to get used to MVC thinking. It wasn't that hard for me to get used to. What's the issue when it comes to MVC? Not sure where to put which code?
1: http://mislav.uniqpath.com/poignant-guide/
2: http://guides.rubyonrails.org/
3: http://pragprog.com/titles/rails4/agile-web-development-with...
4: http://api.rubyonrails.org/
EDIT: Forgot to mention that railscasts.com has awesome screencasts on all kinds of topics.
I also forgot to mention that restful_authentication is really old. Use authlogic.
Also, a word of caution - http://guides.rubyonrails.org is currently based on rails 2.3. http://edgeguides.rubyonrails.org/ is probably the best place to look for the moment if you want to start with 3.0.
The edge guides actually follow the current master branch while the regular guides follow the current stable branch. Since 3.0 is kind of in limbo between the two (as an RC, it has it's own stable branch, but it hasn't been released yet), it's pretty much completely in sync with edge. Once it's released, everything should switch over to guides having info for 3.0 (the index page should list what version it's currently for).
...That was probably more than you ever wanted to know about Rails guides.
For me the problem with MVC thinking is that I am used to my own system of MVC that I programmed for my personal PHP toolkit.
My version of MVC allows me to just write something like:
<form>
<?php databaseInput("tablename",$id,"keyName"); ?>
<?php databaseInput("tablename",$id,"keyName2"); ?>
</form>
It is very simple and works great with key value databases. My code system is designed to automatically detect the type of the key and output the appropriate control, even building dynamic AJAX controls such as input fields with attached google maps if the key is an address key.After getting used to my own incredible easy to use MVC style system Ruby feels complex. I can use the generate script to build scaffolds, but then the generate script does so much that I can't really grasp all the connections.
For that matter I don't even see if it is possible to create a model with key value storage. The Rails generate scripts don't seem to have an option for that.
Perhaps you are correct that Rails might not be the thing for me, but I do really like Heroku, and want to be able to use it to enjoy the ease of scaling a web app by just dragging the slider upward. That means I need to build in Rails.
In addition, I feel that it will probably be better in the long-term to understand Rails thoroughly.
Edit:
I just wanted to add that I have read _why's poignant guide and found it very useful, if a little less formal than I am normally used to. ;) I think that I have enough of a grasp on Ruby itself, and I have already developed a few standalone scripts. What I don't understand is all the things going on behind the scenes in the Rails code, and that is my stumbling block.
In Rails 2, you can't have a model backed by a key-value store. Rails 3, which has a release candidate out, should make that doable.
Sinatra (with and without Padrino) also make it easy to use a k-v store. I think there's a good Redis library out there. I've used rufus-tokyo, which is a ruby library for Tokyo Cabinet, and it's solid. Though now there's Kyoto Cabinet. I'm not sure what the libraries are like for it.
I thought I understood it (yea, model, view, controller, gottit, so what). I figured it was about as important as a folder for css and a folder for scripts. But MVC is the core structure of how rails operates, so it is super important.
A friend of mine who is a rails developer helped me immensely by describing MVC as
Model - Anything that describes the structure of your data and interacts with the database
View - The layout and display of the page
Controller - gets the data from the model and passes it to the view.
I didn't bother with a 'restful' gem, as rail3 (which I decided to learn with) is already restful, so I'm not sure what that gem would have done for you. But it is true, some Gems won't work, I think that is just the way things are with Rails and Python due to different versions, and they being younger languages (though this can happen with PHP packages also I think, I never really used many of them).
I also dove in head first and went with MongoDB with MongoMapper, which I wanted to learn anyway, instead of using mysql and ActiveRecord.
The railscasts are actually quite good, though I actually learned by creating a twitter clone http://teachmetocode.com/screencasts/creating-a-twitter-clon... The tutorial wasn't flawless, but I am using MongoDB and Rails3, so I wasn't expecting it to work perfectly, but I eventually got it all working.
Part of my challenge with Ruby was that it seemed to do SO much for me that I didn't understand what it was doing, but it kinda worked. Then when I wanted to make changes, I didn't know enough about what it was doing to get it to work.
As far as Heroku, I'm yet to actually release a rails app, so I haven't even tried that. I decided to learn Rails because it seemed like every developer I've teamed up with over the past year has been a ruby dev person, and I figured it's easier for me to learn their language and add to my quiver than get them programming in PHP which some of them knew, but didn't really like.
After using Ruby, I can't say that I'm a complete convert, as I think I could still get much done in PHP at about the same pace, but I think we're moving into a rails world.
MVC does make sense when you get used to it. Best of luck.
This is my EXACT problem, but worded much better than I worded it. Thanks for the MVC description and the link to the screencast.
It takes you through building various demo apps, using ruby, rails (separately at times), git and heroku. It doesn't bog you down in too much detail or theory, instead it introduces ideas in bite-sized packets and then shows the code relating to the theory immediately. I'm learning rails 3 from it, without ever having picked up much of rails 2. Highly recommended. The guy who wrote it, Michael Hartl, was in YC too.
More specifically, I have found railscasts and the official rails guides plus railsdoc to me infinitely useful. I usually look for a railscast to get the overview of the thing I want to use then look for a guide and then move into the rdoc for deeper understanding.
The first book will give you good coverage over what makes Ruby different. Most importantly it will give you an understanding of how the fancy stuff that Rails does is possible. The second book is a very good foundation book for Ruby. After this I think you'll be able to dive into Rails with much more confidence and understanding.
You're on the right track, you just may need a helping hand here and there. Try the #rubyonrails IRC channel on Freenode; it's very active, and tends to slant towards the newbie crowd. It may be just what you need.
If you've got the basics of Ruby down, get this book and take it to the next level
http://www.amazon.com/Metaprogramming-Ruby-Program-Like-Pros...
As for the gems in rails..study their code, learn what they try to do, then program it yourself, else you might spend forever fighting with poorly documented and fragile gems, that were never really intended for long term production use anyway..
just my 2 cents..
I just started it last week and have come to really appreciate ruby. My code doesn't look like python anymore :)
Start a dummy project while reading a great book on the subject. This way, you understand the book better because you're using the concepts you've just read.
Sometime, if it's a big framework/language, I like to start with a really small tutorial (See python or Arc tutorial for examples of what I'm talking).