Ruby on Rails commands and conventions - what are they? - ruby-on-rails

I have been making websites in PHP and MySQL for almost ten years now but I have never used a framework. This means I have hand coded everything and I know how the code all works and interacts with itself.
Wanting to expand my horizons I have picked up Ruby on Rails to learn another web language, framework, DB etc. I have been following the Ruby on Rails tutorial and it is going smoothly so far but what bugs me how much of a black box it feels. there's too much magic, and stuff happens just because it does. Example of this "magic" include, if I add to the routes file "resources :users" all of a sudden I have near infinite possible links like /new /user/1 /user/1/edit etc. Or if I want to add a column to my db table I have to do something like this in the console "rails integrate _to_table value:type" and then I have to "rake" the db.
I have been able to make stuff following the tutorial but I don't understand what I am doing. I know part of it will come through experience but I want to know how and why Rails is doing what it does.
What are some good resources, online and books, where I can learn how RoR works?

Yes, it takes a while to know what all the magic is, but you'll get there eventually if you stick with it.
The 'bible' for ruby on rails development is http://pragprog.com/book/rails4/agile-web-development-with-rails
The 'bible' for the ruby language itself is the 'pickaxe' book, with contributions from the ruby language author himself. http://www.amazon.com/Ruby-Programming-Language-David-Flanagan/dp/0596516177
Ryan Bates has done HUNDREDS of free sceencasts and he is famous for having a really great approach, using the framework effectively. Every good rubiest rate these highly. http://railscasts.com/
Many folks find the "zombies" courses really good. http://railsforzombies.org/
Finally I'll offer my own bookmarks site with over 50 sites for rails:
http://www.rormd.com/linker/groups/1
and 20+ sites for ruby at
http://www.rormd.com/linker/groups/4
While you are learning a good IDE can help a lot. I used eclipse, then netbeans then rubyMine (from our friend at IntelliJ, well known for their java editor. rubyMine has the most features. It is not free but for the price (somewhere in the $24-$75 range, depending on special offers) it's well worth the cost.

This is for newcomers if they wants to learn ruby on rails, even don't know Ruby. I can say try this first and jump on others book.
Just hit on below link and see there are two tutorials available for Ruby on Rails 3.0 and 3.2
Ruby on Rails Tutorials link for Rails 3.0 and 3.2
for those tutorials you do not required Ruby backgrounds
even I like Head First Rails, this book is also good for understand - just rails (no TDB), so initial you can set in rails environment and after that jump on above tutorial link

You can see the entire code on Github http://github.com/rails/rails.
The Jose Valim Book Crafting rails application help to understand a lot of internal in rails too

I would say that using the terms "black-box" and "magic" is a quite inadequate and maybe even a bit depreciative. I believe that the difference you are feeling comes from the fact that Ruby is a very different language than PHP, and that it is easier to code high-level abstractions and conventions in Ruby that in PHP. Rails is full of these abstractions and conventions, and these may be quite confusing, specially if you have no ideia of how they internaly work.
Maybe it's not about Rails that you should be reading. I'd say that you should try to understand Ruby in the first place. A good understanding of its blocks, its object model, and its mixins is mandatory in order make that "black-box" feeling go away.
Programming in a modern programming language ain't black magic. Debugging Fortran code by printing the code and using crystals over the papersheets to find the bugs was.

Related

Beginning rails

I have been doing desktop applications since I have started programming, and I have not really looked at the web side of things. Seeing how fast this market is growing, I convinced myself that I should learn a web framework. I learned some PHP, and I found it to be quick, but, after projects get beyond small, it becomes a hassle.
So, looking at recommendations online, I took up Ruby on Rails. Now, when I go through the ruby on rails guide, I don't really feel like I'm understanding anything, or really writing any code. I just feel like I'm editing configuration files. Is this normal? Should I just keep going through the guide, and it will all come to me later?
FYI, I'm using this as a tutorial.
When I coded in PHP, I immediately understood what the code was doing, but, with Rails, I really don't understand how all of it comes together.
EDIT: I am good at Python and C, and not bad at Java, if that changes your answer.
Before you start on Rails, I would start with the pick axe book (Programming Ruby
by Dave Thomas http://www.pragprog.com/titles/ruby3/programming-ruby-1-9) since you have previous programming exprience and make sure you have a solid grounding in Ruby.
Then I would go through the Ruby Koans and do some of the ruby quiz's. Both are fun and great practice.
Then I would start with either Michael Hartl's http://ruby.railstutorial.org/ruby-on-rails-tutorial-book or Agile Web Development with Rails (http://pragprog.com/titles/rails4/agile-web-development-with-rails) make sure you are getting the latest edition.
I would suggest Michael Hartl's tutorial first. Don't worry if you feel led by the nose a bit. I found Agile Web Development with Rails, as with a lot of the PragProg books, to expect me to go out and do a lot of research on my own along the way, like in the guides, because the topic is so big.
Then, if you don't know Javascript, you are going to want get a solid grounding in that as well. The Crockford book is highly recommended, but i found that I had to go through something basic first before I could understand a lot of the points that Crockford was making.
Just remember, despite the fact that everybody talks about how powerful/beautiful Ruby is (it is!) and how wonderful rails is (it is!), normal developers aren't going to tell you that it is easy to learn, at least, not the ones that understand the complexity and depth of both. With both you have to work pretty hard to understand them. With Rails, it takes a while to remember all the conventions.
Maybe you should try other tutorial, for example this one http://ruby.railstutorial.org/ruby-on-rails-tutorial-book
In this tutorial, author shows how to build a real app, IMO this is the best way to learn a new technology, by practice.
It's not normal - it's nice!
With Ruby on Rails we stick to a convention over configuration principle.
You should understand rails conventions. With that principle you can get a working site in 15 minutes without any configuration or coding based on best practices.
If you need something special you can code it by your own.
Small advice: buy a book. It is worth it.
I would strongly recommend this online tutorial - "Rails for zombies" -> http://railsforzombies.org/
I have walked through this tutorial and I know two other friends that have started with Ruby on Rails using this site. It is really fun and easy to begin coding.

Rails learn's confusion

This is a beginner's rails learning confusion. When I learn rails, from time to time, I feel frustrated on rails' principle "Convention over Configuration". Rails uses heavily on conventions. A lot of them are just naming conventions. If I forget a convention, I will either use the wrong naming and get unexpected result or get things magically done but don't understand how. Sometimes, I think of configuration. At least configuration lists everything clearly and nothing is in fog. In rails, there seems a hidden, dark contract between you and the machine. If you follow the contract, you communicate well. But a beginner usually forgets items listed on the contract and this usually leads to confusion.
That's why when I first pick up rails, I feel like it is somehow difficult to learn. Besides, there are many other things that could be new to a learner, such as using git, using plugins from community, using RESTful routing style, using RSpec. All these are new and come together in learning ruby and rails. This definitely adds up difficulties for a beginner.
In contrast, if you learn php, it wouldn't be that bad. You can forget many things and focus on learning php itself. You don't need to learn database handling if you know SQL already(in rails, you need to learn a whole new concept migration), you don't have to learn a new decent unit test(in rails, usually they teach RSpec along the way because rails is agile and you should learn test-driven development in the early learning stage), you don't have to learn a new version control(in rails, you will be taught about git anyway), you don't have to use complicated plugins(in rails, they usually use third-party plugins in textbook examples! what the hell? why not teach how to do a simplified similar thing in rails?), you don't have to worry RESTful style.
All in all, when I learn php, I learn it quick and soon I start to write things myself. Learning php is similar to learning C/java. It tastes like those traditional languages. When I learn rails, it is more difficult. And I need to learn ruby as well (I believe many of you learn ruby just because of rails).
Does anyone have the similar feeling as I have? How do you overcome it and start to master rails? Hints will be welcomed. Thank you.
You do need to learn Ruby. Ruby is a language. It has its own quirks. You don't need to learn a lot of Ruby, but you can't learn no ruby and expect to write anything decent.
Next, you do need to learn the Rails conventions. Learning the conventions means that you don't need to learn the Ruby networking classes. If you don't want to learn the conventions, then writing anything of value will be difficult.
It's really no different than learning C# (as a language), then learning an MVC framework, like ASP.NET MVC, or FubuMVC.
Yes, you throw up a anything in PHP, learning a lot less in the process. But investment is valuable. Your education is valuable.
Learning takes time. Modelling is important, and I've seen some ugly Rails code because the authors were poor modellers. Those poor models turned into ugly databases. But it still worked! It met that customer's needs.
You comparision Rails with PHP does not hold, since Rails is a framework and PHP is a language. You should compare Ruby with PHP, or Rails with some PHP framework (I am not familiar with PHP frameworks and do not know an example)
But you are right about the things that 'magically' happen with Rails. I too had problems understanding them and looked many things in the Rails code to see what was actually happening and why.
To learn Rails you should first learn the language on which it is build (like you should do with any framework IMHO), so learn Ruby first. Personally I liked Mr. Neighborly's Humble Little Ruby Book a lot. It is written in a easy and nice way and is not boring/serious like a lot of books on languages.
After that I read/did all tutorials/guides on http://guides.rubyonrails.org/ they covert the (important!) basics and tell about the Rails specific things you are writing about.
When I first heard of Rails the claim was that you could build a web app ten times faster than the other frameworks. I always thought this was an exaggeration.
Most of the conventions are hard to remember if you don't have ten years of doing it the 'configuration' way. So, for someone new to web development it is hard to remember all the conventions and to understand why they are important. I definitely did not see a ten time increase in productivity. Routing, for example, probably started nice and simple but grew more and more complex. I think some effort should be made (perhaps by the people writing Rails books) to not try and throw every capability out there to confuse newbies.

Ruby On Rails Web Application Development From Scratch?

Background
I am interested in getting to grips with some Ruby On Rails. I've got 4 years experience programming in C#, ASP.Net, ASP.Net MVC, SQL Server and more recently Silverlight etc. Obviously I've got a pretty good understanding about the various implementation routes that you can go down when writing web applications using C#, the issue is that I have literally no clue about Ruby On Rails, other than that Ruby is an awesome pure object oriented language and that Rails is a very quick way in which to build web applications using Ruby.
What I'm After
So essentially I'm after a session that fills in the blanks, and helps me to understand the various ways of building web applications using ROR. On top of this, i've found a few tutorials but they seem to be quite vague, so any documentation/samples would be very handy to help get me started.
More Detail
Popular IDE'S to use for development (I've heard RubyMine is good from JetBrains).
Possible database implementations to use (I know MySQL is an option but which version?)
Is HTML/CSS used to style the web apps?!
Interface plugins if used?
General route to producing a highly Web 2.0 site that encompasses a fantastic user experience and a beautiful interactive interface.
...You get the idea, I just need a bit of guidance getting clued up.
Help greatly appreciated :-D
I'd highly recommend starting by reading:
Programming Ruby (also available online)
Agile Web Development with Rails
You should start with the first one, but don't read it all the way through. Once you get the basics of Ruby down, you can switch to the Rails book, but feel free to switch back and forth as you get more familiar with both Ruby and Rails.
The books are both very well written, and they're actually fun to read as far as technical books go. They do a great job of explaining the basics to a total newbie and also really digging in deep. You'll have all of your initial questions answered within a few hours.
When I tried to get into Rails, I bought this Rails for .NET Developers. It was quite useful to get going. After that, the most value I found was watching railscast videos.
For an IDE, I use Netbeans.
Different people learn different ways, but one thing I find to be very helpful for getting a real "feel" for Ruby on Rails is screencasts. The Rails site has a whole section devoted to screencasts. For example, with the 15-minute-blog video, you can actually watch someone work on the blog app and see all the steps along the way. It's not necessarily more informative than, say, a book, but it can be easier to grasp when you're actually seeing it.
The official Rails Guides are kept well up to date -- begin with the Getting Started guide, Railscasts provide quick how-tos on lots of common tasks, and the Agile Web Development with Rails (3rd Edition) book is excellent if you want to sit down and read how it all works.
There's also tons of sample code on GitHub, where you'll find just about all the plugins available as well as lots of well-designed Rails apps that will show you all the best practices.
Regarding specifics you asked about:
Many Rails developers don't bother with an IDE (they just use text editors such as TextMate on the Mac). MySQL is popular for production but for local development, Rails is set up to use SQLite, which is quick and easy. Many developers are moving to a NoSQL datastore such as MongoDb because development is quicker without schemas and migrations. You'll use HTML and CSS but you may use Haml to abstract your HTML templating. For an interactive "Web 2.0" site (as you ask) you'll want to be become familiar with jQuery and CoffeeScript.
You asked the question back in October 2009 but I'm sure other people will continue to want suggestions for the best way to get started with Rails. I hope you've already become a Rails ninja!
i started ruby on rails a few days ago using http://ruby.railstutorial.org/ruby-on-rails-tutorial-book by Michael Hartl. so far so good.
This is my experience, I'm at the stage where I can build simple apps. I am comfortable with code, at least to go to the right sources.
Hartl Tutorial ... go through this at a steady pace, just to understand the overall basics. No way you can absorb everything there.
Why's poignant guide is great to understand how to read code through a story, making things enjoyable and memorable.
Agile guide to rails. This put eveything together, I went through the exercises but stopped near the end. I read what I thought I needed to know how to build something my work would use.
Using railscasts to supplement my app building.
I would recommend as resouces to use apis, irc #rubyonrails, and stack overflow. You would be surprised how people contribute and help you through problems you encounter.
Re: IDE
Most Rails developers use VIM. Or at least the better ones use VIM.
It's more powerful than an IDE. I know and use at least 5 languages and VIM works well for all. I use YADR. If you were with a team, sometimes using VIM or Emacs or Geanie are your best options.
Re: Books
You should read a Ruby book before anything. And by read, I mean, try the examples.
The best book I've read on Ruby on Rails is probably Ryan Biggs' book.
Engineering Long-lasting software would be a good book focused on teaching you some Ruby fundamentals for practical reasons.

Learning Ruby on Rails with Pragmatic book

I only have a background knowledge of java and C, and a bit of unix (learned from the first year Comp Sci) and i do know bit about HTML/CSS... anyways so i've started using the book and the book said that we don't need to know html or ruby or css and that book would be kinda teaching all that as we go along..
And i'm at the part where we create a cart for the online store website, but i find that they just add a ton of html/css of ruby codes without really talking about it, and moving on.. I heard that this book was the best of there for ruby, i just focus on the stuff they mention, but i was wondering if i'm supposed to actually just look at other stuff when they add the CSS or HTML tags or ruby codes... i feel that this book is flying, without much explanation..
Should i just keep going with the book, or go back and study every line of all those codes they just put in the program?
I used this book in my first job and failed miserably. It was my first time and and didn't knew Ruby but was asked by my team leader to just go by this book. And I miserably failed to do anything other than the said methods in the book.
I suggest if you want to t have good grasp at web development, you need to know HTML, CSS and Javascript at a very decent level. After thatstudy Ruby. Then you can go through this book.
Now there was once an article online by a prominent fellow in the rails community saying something worse about this book. But since it isn't online anymore I assume that the blogger realised he was wrong and the book is indeed good. So just go about and find it for yourself. But as I said go through all the other necessary topics I mentioned before you jump into rails.
I've used the this book, is good but as you said they some things lack explanation. Usually the best thing you can do is pretty much use google or stackoverflow to lookup this things that you just don't understand. I was pretty much like you, 0 HTML or Rails, but after 2 weeks of reading code and looking for explanations on the web I can now pretty much understand all of the code, and afterwards everything is pretty straightforward.
My best recomendation is that you modify all of the code they give you, this will force you too lookup everything you don't understand. The good thing is that the code on the book is pretty good, and they try to teach you good programming practices on the way so stick to the book.
The HTML/CSS should be easy to pick up, but if you're having trouble following the Ruby code, I'd suggest you start with a Ruby off-Rails book. The Pickaxe book comes to mind. You can find the 1st edition online. Also the Ruby Way helped me to "get" the Ruby way of doing things.
I would continue with the book, it really is good. However, you might want to look at some other books as well including (but not limited to) Simply Rails 2 and Learning Rails.
I found the Pragmatic book to be a good start and the other two to complement it rather well. After that, just have some fun digging into some of the internals.
I would study the code thoroughly. I think you'll find that (if you keep working at it) ROR is pretty amazing.
I think your best bet will be to keep going at a steady pace on the book - going into more detail if you get lost, and if necessary grab a snapshot from online to keep pace if you break things.
From there I would start branching out into many of the other excellent resources available. Pragmatic Programmers have a book called Advanced Rails Recipes that I hear is also fairly good.
Since Rails is still moving rather quickly your best bet will likely be, once you have a handle on things, to start following some of the latest news. Ruby Alltop might be a good place to start looking for more resources. I would suggest going through as many Railscasts as you can - they are pretty much the definitive place to pickup Rails concepts quickly.
I would highly recommend supplementing the books with screencasts. Ryan Bates in particular has done an enormous amount of Rails screencasts at Railscasts, which are freely available. He has also done some paid screencasts for the Pragmatic Programmers site which are much more in-depth, and very helpful.
Creating multi-model forms was a bit of an early sticking point for me, and Ryan's Pragmatic Screencast series on forms was very helpful. I would also recommend the ActiveRecord series.
I started Rails when it was 1.3. I followed the second edition of Agile web development with Rails. I was facing hard time finding how the things were happening. As I did not have any experience of web development this was more painful. I followed the book and created the depot application twice but I still did not get very much from this book.
I was having trouble understanding the Ruby code mainly. As said by "listrophy" on #rubyonrails
Using rails without knowing ruby is
like trying to write a menu at a
chinese restaurant with only an
english-chinese dictionary.
You should get yourself up and running with Ruby first only then you should dig into Rails. I highly recommend you the Ruby for Rails book by David Black but for Ruby only. Read part 2 and part 3 only from this book. The things about Rails in this book is crap IMNSHO. When you are done with Ruby from this book, carry on your journey with the Agile rails book.
When you are done with all this, you can check out The Rails Way, The Ruby Way, Pro ActiveRecord books.... The list goes on and on... :)
The depot application in the Agile book is a great example of a sample Rails application. However I suggest you to check out Open Source Rails for some more sample apps. Rails Guides also have some very good tutorials on rails. As said by everyone else Railscasts by Ryan Bates has some very high quality free rails screencasts.
FYI I have a little knowledge about HTML and very little about CSS. You can not learn these technologies by following some book. You will learn these with the experience and time. Although some books can give you a good start. But I do recommend you to learn Javascript-Ajax and stuff. For this purpose you should use libraries like Prototype or Jquery. I recommend Jquery as this is much more easier to learn and also more powerful.
HTH :)

Gettings started with Ruby on Rails 2.0 for Windows

So like many people, I'm excited about Ruby on Rails. Being a Windows user, I downloaded InstantRails, got it going, and followed along with the screencast on how to make a blog with RoR 2.0 in fifteen minutes. I used Notepad++ as my text editor, because that's what I've traditionally used for writing the PHP-based websites I've done in the past. I was a little envious of Mac users and how they get the really attractive-looking TextMate, but I managed to follow through the entire screencast and get everything working smoothly.
However, I was lost most of the time.
I know plenty of programming and scripting languages over the years - C++, JavaScript, PHP, HTML, and Lua just to name a few. I don't know Ruby, but I understand a lot of how it works, as far as the syntax is concerned, but I don't understand a lot of the logic behind why certain files do certain things, and that sort of thing.
Also, I tried Aptana with RadRails, but found it difficult to set up. Is there any concrete tutorial for getting it set up and working fully with Ruby on Rails 2.0?
Should I maybe just wait for more RoR 2.0 tutorials to come out before attempting to learn RoR? Or should I just plow on through and experiment until I figure it out?
Also you may want to look into NetBeans, it has great support for ruby and rails. They also provide several focused tutorials and even viedos.
http://www.netbeans.org/kb/trails/ruby.html
Another excelent source of focused tutorials is http://railscasts.com/ by Ryan Bates.
On the ruby side, I strongly recommend The Ruby Way, and if you are into screencasts, the Pragmatic Programmers have some cheap and excelent ones on ruby object model and metaprogramming by Dave Thomas.
Pragmatic Programmer's Agile Web Development with Rails is an excellent book to get started with.
There is a RoR 2.0 BETA book available as well.
If you are really serious about learning Rails, my advice is to get a good book and read it (I know.. programmers don't read books, but you should!). A "good book on Rails" usually contain a chapter on Ruby, but there are plenty of resources on the web to get you going.
According to Ruby on Rails guides:
It is highly recommended that you
familiarize yourself with Ruby before diving into Rails. You will
find it much easier to follow what's
going on with a Rails application if
you understand basic Ruby syntax.
Rails isn't going to magically
revolutionize the way you write web
applications if you have no experience
with the language it uses.
I'm personally using Simply Rails 2, which uses (surprise, surprise) Rails 2. It walks you through the development of a Digg clone.
If you still don't wanna use a book, you should check out Ruby on Rails guides and the Ruby on Rails Wiki. AFAIK, They are being regularly updated to keep up with new releases of Rails.
The Rails Way is also a good book. I use it everyday as a reference book.
You could always check out the awesome Peepcode screencast series:
Rails 2 from scratch part I
Rails 2 from scratch part II
You'll be off and running in no time after watching those. I would also recommend Railscasts, a (free) weekly screencast on Rails, usually focusing on a single feature or implementing a concept in a wonderfully produced manner.
From what I've read, though, it looks like many of these books and such are now at least partially outdated with the advent of Rails 2.0. Is this true?
InstantRails has not been updated for a while, check out Rubystack, which is a similar project but we also include a bunch of other tools: Apache, MySQL,Imagemagick, etc.

Resources