Design Patterns with rails - ruby-on-rails

I'm doing a web application for my Software Enginearing' exam. I decided to use Rails framework and I'm trying to learn it.
During the course we have studied Design Patterns from GoF, but I don't find anything interesting for Rails.
Can anyone adress me to some sources that can help me?

I read this one http://www.amazon.com/Design-Patterns-Ruby-Russ-Olsen/dp/0321490452 and I found it very interesting. Both in terms of design patterns and in the way it goes under the hood of things people usually know about ruby.

Related

Backbone.js or Ember.js with Ruby on Rails

I was looking for information comparing Ember.js and Backbone.js for use with a Ruby on Rails backend. Does anyone have experience working with both of these client side frameworks and would be willing provide some insight around them?
Both are great, and you can't make a bad choice imho.
There is a good thread on this subject on Quora, with an answer from one on the Ember.js author, Yehuda Katz: http://www.quora.com/What-are-the-key-differences-between-Ember-js-formerly-SproutCore-2-0-and-Backbone-js
A quote from the thread (Austin Bales)
A lot of the differences between the two come down to this: SC2/Ember have made a few decisions in advance about the tools and workflows you'll use. Backbone has very few opinions on matters of templating, rendering, hierarchy, and KVO/Binding – in Backbone there's almost always "More Than One Way To Do It" and almost never a predefined way. In contrast, Ember provides a little more infrastructure and default options out of the box.
The fact that Ember.js is opinionated is probably a good thing in the long run I'd say. It's kind of the same philosophy as rails where they often make choices for you.
I actually have to make this choice at work as well. I tried working a little bit with both, and I have to say, I feel more confortable with Backbone, but it's really not a well informed opinion ;)
ps: check this out: http://addyosmani.github.com/todomvc/
It's a todo app implemented with all the popular frameworks. It could help you compare the two.
edit: Since I wrote this answer, I've been trying to learn Ember, and I'm really liking it. Here is an AWESOME blog about ember, everything is very well explained, clear, in depth: http://darthdeus.github.com/.
Ideally, you would master both, as I feel that they have different use cases now.
Gordon Hempton has written a nice article about JS frameworks here: http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/

Rails on Rails taking it to the next level

For the past few months i've had the feeling that i reached a boundry in my knowledge of Ruby on Rails (RoR) development. I've developed large and small applications for both big/small clients and friends / hobby projects. I know how to develop these applications and it's beginning to feel a little bit tedious. I want to take my programming skills to the next level, me having a little experience with Javascript i enduldged myself in some good Javascript books and learned alot! But now i'm back stuck at the same RoR level that i've been for the past few months. and i want to get that knowledge boost i got from the Javascript books.
I really want to contribute to alot of open source projects but when i look at the source code i get the feeling that i dont know enough of the code and that i will become a irritating burdon to the main developer(s) of the project(s). This is just some uncertainty of mine but i dont want to tire/irritate other developers...
I feel stuck and i dont know what to do to up my own level. I try to read the source codes but often i get stuck with mainly the question "why are you doing this, and what are the benefits of it? And how does it work?". I know i want to up my knowledge of both ruby and rails but i dont know how to do this. In my time programming RoR it's been very difficult for me to pinpoint my "skill level" knowing i can always up my skills. So knowing this i started with some basic Ruby books: The well grounded Rubyist and Beginning Ruby. These were great books i learned some nifty little tricks but that's about it.
Do you guys recommend any resources and or books. I don't have alot of experience with other languages than Ruby / Javascript. But i really want to learn, i don't have a solid programming background because it mainly evolved from hobby to work. I want to contribute to open source projects and work and mainly learn from other great developers. I'm stuck and i don't know where to start.
Thanks in advance.
A few books:
Eloquent Ruby
Rails Anti Patterns
Crafting Rails Applications
Then, armed with knowledge, you'll be able to read code (your first and good intuition): that's a great source of inspiration.
There's a lot of good material at Railscasts which is worth looking through. You can learn a lot about current practices, something doubly important when a lot of the Rails material out there is for 2.x or 3.0 and doesn't reflect the state of the art.
The best way to improve your skill is to find new challenges to exercise yourself. You'll need to work on general Ruby and general programming as well as improving your knowledge of the Rails framework.
Set aside time to read and understand the various APIs you're being exposed to. The more you know your toolbox, the less time you'll waste trying to do something that's already implemented. APIDock is one of the many documentation aggregators out there for Ruby and Rails. As Ruby is generally quite readable, it's even educational to browse through the source for the libraries you use and see what methods are offered as well as any insight you might gain from observing how they're implemented. Often there are interesting use cases that are never fully documented but will serve you well when you need them.
There's a lot more to say, but really, it's a long journey. That's why people write things like Teach Yourself Programming in Ten Years as a counter-point to the "Teach Yourself X in 21 Days" books plague the industry.

Do I need to know Ruby in order to learn Ruby on Rails? [duplicate]

This question already has answers here:
Closed 12 years ago.
I've read several other questions about material in order to learn RoR. But my question is can I start learning RoR without Ruby?
It's clear that the other way around is better, but I would rather try this way if it makes sense (somehow). Or learn both in parallel...
Well, given that Ruby on Rails is just Ruby written in a particular fashion (read: framework) yes you will need to learn Ruby.
You will need to learn these things about Ruby (amongst other things):
Everything Is An Object. Everything. Yes, even 2 and "foo"
Class Inheritance and What It Does(tm)
How to tell the difference between class and instance methods
Modules and how to use them correctly (class_eval Is Your Friend)
People write gems. Use them. Re-inventing the wheel is fine and dandy for learning but re-inventing it because you think your method is better is not.
And these things about Rails:
Do not fight conventions.
Do not fight conventions.
Model code goes in the model.
Controller code goes in the controller.
View code goes in the view.
Helper code goes in the helper.
Ask yourself "Does Rails have a helper for it?". If the answer is "No" ask somebody else. The answer is likely to be "Yes".
And these things in general about learning:
Google it.
Google it again.
If the answer you seek is not within Googling distance, formulate it in a way that is kind to those who may know the answer (such as you've done with this question!)
Appeal to people's greater motives. How can helping you, help them?
Try not to be too much of a help vampire.
If asking in an IRC channel, use a pastebin service such as http://pastebin.com, http://pastie.org or http://gist.github.com
Second rule about asking in IRC: Don't ask "any ideas?" after your question. Your question should already ask this by itself.
And finally: Love what you do.
People used to say that you could learn RoR without knowing Ruby (including DHH, if I am not wrong).
But in my opinion, if you also know Ruby, you can do a lot more stuff than without knowing it. And the knowledge would be very helpful when you debug or troubleshoot your programs.
So my suggestion is learn both in parallel.
You can. RoR is in a way a domain specific language, since a lot is defined for you and putting a simple application together can be like following a straightforward recipe. It would of course be better to learn the language properly, but many people don't.
The Ruby For Rails book tries to teach you both at the same time, so you might want to look into getting that one. I haven't read it but I hear it's pretty good.
Obviously :) ... if you really want to develop good web apps ...
But it will also be interesting to first get your hands wet with some RoR sample applications using inbuilt features that RoR provides... and then learn the details(which will require knowledge of Ruby)
If you avoid learning Ruby, (that many of the RoR developers do)... then you will find yourself stuck at position and going through an alien code. And eventually you might leave RoR out of frustration. I have seen many of such cases.
The question you ask is slightly ambiguous. Specifically, you could be asking "Can I learn Rails without first knowing Ruby?", or "Can I learn Rails without having to learn Ruby too?".
The answer to the later question is probably no, if you want to be particularly functional with it. Without knowing Ruby, it would be hard to take advantage of much of Rails' power.
The answer to the first question is most certainly yes. While knowing Ruby first would make learning Rails faster/easier, you can easily learn both at the same time. That's actually how I learned Ruby/Rails, by taking a site I had to implement first in Java and re-implementing it using Rails.
You need to know both, The RoR framework is an organizational and convenience system if you will, what it organizes is your ruby code.
If you have programmed before then here are most of your answers:
http://www.ruby-doc.org/core/
http://railsapi.com

can users who have used both Django and Ruby on Rails give a little comparison of using them?

Duplicate: Django or Ruby-On-Rails?
I have been reading on Ruby on Rails, and it seems like on some threads, some users like Django a lot too?
Can someone who have used both give some insight about using them, such as
ease of use
productivity
fun factor
deployment issues
or any other framework you'd highly recommend?
Both are excellent frameworks. Though, I've found Rails to be more suited for the agile developer. For the most part, you'll run some generators to get the files you need as placeholders for your code. Things will work right away, and you just build up from these conventions. It's really flexible and has a large community, lots of innovation and interesting practices are being put into Rails. It's development cycle seems faster paced than Django.
After only touching the surface with Django, it has some interesting differences. As far as I know, you don't get the schema migrations like Rails has out of the box. But you get an extremely simple CRUD mechanism for your models with the extensible admin interface, which is great for testing/managing content. The entire project is documented really well, from the Django Book to the vast amount of information on docs.djangoproject.com.
I personally prefer the Rails way of doing things. But honestly, you need to try them both to see what works for you, and since we're talking about two very good, yet totally different frameworks, it's a tough decision to make either way. So, if you already know Ruby or Python well enough, start with what you know and just go from there. Once you understand how one works, you'll be able to evaluate the smaller differences yourself. Hope that helps.

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

Resources