Rails learn's confusion - ruby-on-rails

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.

Related

Ruby on Rails commands and conventions - what are they?

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.

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.

cakephp or ruby on rails

I've put some of my free time on reading/learning about cakephp but now I'm wondering if will not be better to switch completely to ruby on rails.
Can you give me the good and the bad of those tools, when is about web-development?
many thx
Why switch? Since you've got a head start on CakePHP, take a little break.
Learn some Ruby on Rails for a while, then switch back to CakePHP when the mood strikes you.
That way, in the end, you'll end up knowing two languages/frameworks rather than just one. It's always better to get as much exposure as possible. Each has its benefits and downsides, but why not learn enough to make the decision yourself?
Neither is better than the other. While one may be more suited to particular applications than the other, they are certainly both good frameworks.
PHP is said to be faster, Ruby is objectively a better designed language. These probably make more of a difference than the framework itself - you can always modify the libraries or write your own classes to make the framework do what you want it to.
My advice is to stick with what you know if you are happy with it - learning a new framework is a long process. If you have issues with Cake or you're keen to try something different, Rails is definitely worthwhile.
I recently read a good article from a developer with a CakePHP base who just completed a large Ruby on Rails project.
http://www.jimmycuadra.com/blog/10-from-cake-to-rails
He details where Rails is stronger than Cake but also the other way around. Another blog here compares Ruby and PHP.
http://developingwithstyle.com/articles/2009/06/09/10-reasons-why-ruby-is-better-than-php-reason-5.html
personally i would choose cakephp at this moment. php and mysql are very common on most web hosting packages, even free ones. it is based on php and there is a huge amount of resources to learn and get help from. you can reuse many already written classes.
regarding the speed of cakephp, there are ways how to speed up cakephp in the production environment through the ways you code and caching.
I would choose ruby on rails because
ruby is fun to write
there is a great community
there are more high quality resources like www.railscasts.com and teachmetocode.com

How does ruby on rails work?

I'm a PHP developer who knows a little bit of Ruby. I want to learn Ruby on Rails, but most of the resources I've come across treat RoR functionality as "magic" -- i.e., it has a certain internal consistency, but don't bother asking how it works in terms of Ruby, MySQL, etc.
Anyway, I want a deep understanding of how RoR works, the design decisions that went into building it, etc. In particular I'm interested in ActiveRecord, but really I'm looking for the whole package.
Any books / sites / advice welcome.
The books "Agile Web Development with Rails" and "The Rails Way" are both pretty good. "Pro Active Record" goes really in depth for Active Record, but doesn't touch on too much else. The podcast Railscasts sometimes just uses the magic, but sometimes it explains what is really going on. Various blogs such as Art of Mission can get into what your looking for.
Additionally, using the ruby-debug gem gives you a much better understanding of what is going on - you can step into what is running behind the scenes.
There are two areas here that can be examined separately:
General concepts (which include design patterns, general attitude principles like DRY and CoC or even agility etc.) since they are the principles behind many design decisions in Rails. Any of these concepts can be studied independently of Rails (since they are general programming concepts). It's good to have at least some understanding of these before digging any deeper. There are many sources about such general principles all over the net (aforementioned Martin Fowler's site is one of the better sources for grasping such concepts).
The way Rails implements these concepts into its corpus. There are, again, two things to have in mind here. Since Rails heavily exploits features of its mother language, it's crucial to understand Ruby's peculiarities (such as mixins and plenty of Ruby's dynamic features). The last thing to understand is how Rails uses these features, ie. how it's broken down into classes and modules, how many of its features are dynamically created on the run and so on. For this purpose, I highly recommend book Ruby for Rails from David A. Black (which is exactly about Ruby, its peculiarities and the way Rails uses them). While this book might be a bit out of date, I think it's still invaluable in its content.
If you really want to know how it works, you can just look at the source code. The online API docs let you see the source code of every method right in the documentation page.
ActiveRecord in Rails is based on Martin Fowler's Active Record pattern. It's basically an ORM (object-relational mapper). It's not even really that sophisticated as far as ORMs go. Java Persistence with Hibernate has a good overview of common ORM concepts.
This one might fit here well too -> http://railsforphp.com/
This is sort of a tangential answer to your question, but I, too, came from PHP development over to Ruby/Rails dev, and it was a big transition for me. As PHP devs, we're used to getting into the nitty-gritty, to to speak, and not being prevented from looking under the hood.
By design, Rails is a black box. You're supposed to learn Rails, almost as a language itself. It's a new way of thinking of web dev, especially from a PHP dev's perspective, though this idea is not uncommon to programming in general.
Not bothering to look under the hood may be the best way to start doing things "the Rails way."
Jamis Buck has a nice series of "Under the Hood" articles on his blog that cover some aspects of Rails' internals.
The "magic" in Rails involves method_missing and the concept of metaprogramming. Dave Thomas of The Pragmatic Programmers created a set of screencasts on metaprogramming Ruby.
PHP has a somewhat-equivalent function called __call, and PHP 5.3 introduced __callstatic. You might take a look at those, as well as search Google for "php metaprogramming", for some reading material on implementing Rails-like behavior in PHP.
I found this site a good starting reference:
http://www.tutorialspoint.com/ruby-on-rails-2.1/index.htm
It assumes MySQL in its examples.
I am sure you can find heaps and heaps by just googling for "ruby on rails tutorials", though.
ruby metaprogramming magic in rails: look at books by Rappin "Professional Rails" and Ediger "Advanced Rails", in addition to Black "Ruby for Rails" mentioned above
Naming conventions are important:
http://rails.wincent.com/wiki/Rails_conventions
http://www.softiesonrails.com/2007/10/18/ruby-101-naming-conventions
If you really want to understand Rails, read the source for the bit of Rails that you want.
/Library/Ruby/Gems/1.8/gems/ on OSX or freeze rails and have access to it in your RAILS_ROOT/vendor/ directory

Learning Ruby on Rails any good for Grails?

My company is in the process of starting down the Grails path. The reason for that is that the current developers are heavy on Java but felt the need for a MVC-style language for some future web development projects. Personally, I'm coming from the design/usability world, but as I take more "front-end" responsibilities I'm starting to feel the need for learning a language more intensively so I can code some logic but especially the front-end code for my UIs and stuff.
I've been trying to get into Python/Django personally, but just never invested too much time on it. Now that my company is "jumping" into Grails I bought the "Agile Web Development with Rails (3rd Ed - Beta)" and I'm starting to get into RoR. I'd still like to learn Python in the future or on the side, but my biggest question is:
Should I be learning RoR, and have a more versatile language in my "portfolio", knowing that my RoR knowledge will be useful for my Grails needs as well??
-OR-
Should I just skip RoR and focus on learning Grails that I'll be needing for work soon, and work on learning RoR/Django (Ruby/Python) later?
Basically the question revolves around the usefulness of Grails in a non-corporate setting and the similarities between Rails and Grails. (and this, while trying to avoid the centennial discussion of Python vs Ruby (on Rails) :))
Mmh, I don't know how to say this. Some people might bash me over this.
Language (Groovy and Ruby)
As a language I reckon Ruby is more funky compared to Groovy. Groovy only exists to ease Java programmer as you don't need to learn too much new syntax. But overall I reckon is not as funky as Ruby. Groovy wouldn't be the JVM language that is worth to learn based on attender's vote in this year's JavaOne but instead Scala is the one to go. Besides that, the original creator of Groovy himself does not have faith in the language he created himself in the first place.
Community and Job openings
As for the community, Grails community is not as big as Rails, though since the acquirement by Spring more and more people are using it in serious application. Rails has more job openings in the market compared to Grails (that is if you want to invest in looking a new job).
The framework (Grails and Rails)
But, as a framework, if you really care about maintainability and need access to Java framework and legacy Java system, Grails is the way to go as it provides cleaner access to Java. Grails itself is built upon several popular Java framework (Spring & Hibernate). Rails itself IMHO is funky like Ruby itself, but it's funkyness costs you maintainability. Matz himself prefers Merb over Rails 2 because Rails create a DSL on top of Ruby which is really against the Ruby philosophy. And I reckon because Rails itself is opiniated, which in turn if you don't have the same opinion as the creator, it might not fit your needs.
Conclusion
So in your case, learn Grails as that is the company's consensus (you need to respect the consensus) and if you still want to secure your job. But, invest some time learning Rails and Ruby too if you want to open a chance getting a new job in the future.
Just a bit of a question, is the reason they are choosing Grails because Groovy is closer in syntax to Java than Ruby, or because they want access to Java?
If it is the former, then I would say try to focus on Grails since that is what you will be using. If it is the latter, you might want to see if the development team is open to using JRuby.
I have never used Grails or Rails before, but I have used Groovy and Ruby before, and as a language I think Ruby is much cleaner and more consistent, and the team might enjoy production more. As a platform, Rails has been out longer and has a lot of attention, so I would imagine it is a more stable platform to use with more fleshed out features.
JRuby has full access to classes written in Java, so this is why I would say consider trying Rails. If it is too late in the decision time to consider it then I guess you can just ignore this post.
Basically, if you just want to hook in with Java, then JRuby is an option you should consider, but if the team is afraid of non-Java like syntax, maybe continue as is.
I would learn both. They are both up and coming technologies. Learning RESTful coding is a real benefit in any language.
I use GRAILS at work and RoR for side projects. I can say that the RoR community is much larger (I'm talking about RoR vs Grails not RoR vs Java) and very helpful.
Short Answer: They are similar.... what could it hurt?
Just skip RoR. There are really not a lot of similar things(besides the name)
I certainly believe that being enough familiar with Java, plus some experience programming with a dynamic language is more than enough if you plan to do serious development with Grails.
Comparing just only views(taglibs in Grails, RHTML in RoR) and the persistence stuff(GORM vs ActiveRecord) is just too different in the core, to invest time learning the nitty gritty details of RoR. Just dive into Grails, you won't regret.
Edit: corrected typo.
I've been learning RoR and Grails and the latter is far easier to learn.
Both frameworks share the same principles (agile, kiss, dry, duck typing and so..) but Groovy syntax is...well is simply great, something you can learn and use in a blink of an eye.
I truly feel that Grails has brighter future than RoR.
PD: Just in case you find it useful, a college of mine it's working full time with Grails and has a blog with some tips:
http://dahernan.net/search/label/grails
You should just skip RoR and focus on learning Grails that you'll be needing for work.
#Levi Figueira
For one thing, Grails is far more flexible than Rails. Rails is difficult to use with a legacy DB because ActiveRecord has too many design constraints that many legacy DBs didn't follow. Grails, oth, can use standard Hibernate mappings, which can accommodate a much broader range of DB designs.
The Rails community has been very vocal in evangelising RoR, with the result that high expectations have been set and not always met (programmer productivity is good, but ensuring good performance once deployed isn't so easy).
Grails has been designed as the scripted successor to Java, whereas the Ruby-Java integration used in JRuby on Rails, for example, has had to be retrofitted.
I would suggest that you stick with Grails; it may not have the same glitz as RoR, but it's a pragmatic choice; you get improved productivity and the re-use of existing Java libraries.
Jump straight into Grails. I'm sure Ruby/Rails is good but so in Groovy/Grails. I recommend this book.
http://beginninggroovyandgrails.com
Remember the errata is online. There are a couple of mistakes in the book.
http://beginninggroovyandgrails.com/site/content/errata
Also, check out the 3 minute and 30 second demo of creating your first Grails app.
http://grails.org/Grails+Screencasts
This tutorial will show you the basics.
http://grails.org/Quick+Start
Yes Grails is the way to go. RoR is good but it ties you in to the Ruby ecosystem. Part of the effort of learning a new framework or language is learning the class libraries as well as the language syntax. If your co-workers are all Java types you will be much better placed to receive help and support as they will all be speaking the same language as you.
The other advantage to learning a bit of Groovy and Java is that web frameworks like GWT will open up to you. Grails has a GWT plugin and as a front end developer you will appreciate the ease of use and cross browser compatibility.
Also there is at least one hosting company offering free Grails application hosting (http://www.mor.ph/) which means that you can prototype sites at small data volumes before having to pay.
I favor Grails over Rails, but learning Rails will give you a more balanced perspective and actually open your eyes to overlooked things that are possible in Grails.
At a first glance you would think they are completely differente stories, since they are based on extremely different languages (Ruby and Groovy).
Then, after reading a couple of tutorials, you'll realize they share the same principles, scaffolding, duck typing, .. and finally the same goal:
making agile programming feasible.
If you already feel comfortable with terms like IoC and MVC, you'll find any of these options easy and exciting to learn.
I would say no, I'm learning Grails as well, and I've considered this as well, but just learning Grails is pretty big, plus learning Groovy (which granted is easy, but still gotta learn it right?) and all that... so learning Rails would have been just too much.
Yes if we compare grails and rails I would choose grails (I developed some intranet applications in grails).
But Django is superior to both - as python is well hmm a perfect choice.
You might also want to take a look at Clojure, a JVM language that's just starting to get popular. It may be a good choice for a Java-based company since it's compatible with your old codebase, and has a lot of modern innovations going for it. There are some good web frameworks emerging, including Compojure.

Resources