Ruby Learning - Know of any public repos with Ruby code of Intermediate difficulty? - ruby-on-rails

I've been going through Ruby (and Ruby on Rails) tutorials online such as RubyMonk, Codeschool courses, the Railstutorial, and Learn Ruby the Hard Way.
These are all excellent resources, but I feel like I need to see some Ruby code that is actually being used in production in order to advance to the next level. I would assume that a repo like Rails would be considered advanced level - so I'm looking for something a little in-between.
Are there some GitHub public repos that are using a more intermediate difficulty level of Ruby coding that I can learn from?
If you can recommend some that would be an appropriate follow-up based on the contents of the tutorials I listed earlier, that would be great.
I've looked some myself, but I'm asking for recommendations because I want to make sure I'm studying something that is "the right way" to do Ruby and not learning bad habits.

Here's two I've created:
http://github.com/rails3book/ticketee - A light-weight project management system from the http://manning.com/katz'>Rails 3 in Action book.
http://github.com/radar/forem - A forum engine for Rails 3 applications.
Both should have pretty good examples of intermediate code, along with tests.

I published a solution to a ThoughtWorks interview problem that I used as the example for a talk. I'm not sure it's "intermediate", but quite a few things in there might fall outside the range of "beginner", so I think it might be up your alley. There's also a rather robust test suite using MiniTest::Spec and mocha.
For example, I use this approach to cause classes which include a module to register themselves with their base class:
module TaxWorks
module TaxStrategy
def self.included(base)
add_strategy base
end
def self.strategies
#strategies ||= []
end
private
def self.add_strategy(s)
strategies << s
end
end
end
In this example, now you can do TaxStrategy.strategies to enumerate the list of possible strategies, after loading any you care about.
Hope that helps!

If you're into Rails you should have a look at these open-source Rails apps:
https://github.com/rubygems/rubygems.org - Source code for rubygems.org, the Rubygems server/website
https://github.com/ryanb/railscasts - Source code for railscasts.com
Both of these apps are exceptionally well organized, clean and thought out. In the case of rubygems.org it's had tons of contributions from different rubyists and is a great working example of Rails in action.

I think Sinatra is a good start. Take a look at Sinatra's source code and build a small MVC application with some helpers. You will not only learn some ruby but also get a good understanding for how Rails work without the magic. It is made "the right way" and you will not learn any bad habits.

Related

Tutorial teaching Ruby syntax/knowledge required to easily learn rails

I am trying to learn ROR these days and have basic knowledge of ruby, but often working with rails, I get to the point where it seems as if I don't know a bit about ruby.
Just to explain the point, in rails we use has_many keyword. I did not learn any such thing when I was going through ruby tutorials but just came to know that it has something to do with meta-programming in ruby (I have no idea what is meta programming).
So I would like to know if there is any book/tutorial which explain all the points/syntax/concepts of ruby, which a newbie would see while programming in rails.
Thanks to "Jonas Elfström", in simple words, what I am looking for is to know "how Rails uses Ruby"
Thanks.
has_many isn't a keyword, it's simply a class method in the ActiveRecord::Associations module.
It's documented here and you can even view the source if you scroll down a bit.
Associations are a set of macro-like class methods for tying objects
together through foreign keys. They express relationships like
“Project has one Project Manager” or “Project belongs to a Portfolio”.
Each macro adds a number of methods to the class which are specialized
according to the collection or association symbol and the options
hash. It works much the same way as Ruby’s own attr* methods.
If you already know Ruby the Rails Guides could get you going but it might be easier to learn from one of the books listed at the documentation page or by watching a couple of screencasts.
For books about Ruby I've never seen such praise as what Eloquent Ruby gets.
There's a tutorial called Learn Ruby the Hard Way
(written by Rob Sobers of Fog Creek Software)
I tried lately this: http://pine.fm/LearnToProgram/ which helped me a lot because there are one or two concepts that had slipped. I started long ago with an arcane version of this.

Would Ruby on Rails suit my work..?

I wanted to make a web site with the following basic features- (1)User registration for buyers and sellers. (2)profile pages (3)A buyer should be able to post work and should get profile links of the corresponding seller who has expertise in that work.
As time progresses i would want to add more features to the site.The freelancer sites where user can post jobs and get bids is the best example of the work.
(1)I want my code to be maintainable as i woud be adding features later on. (2)It should be quick to develop. (3)Resources should be available(not the entire thing, atleast in bits and pieces) for the above requirements and should not be tough to find for future enhancements. (4)Design should be decoupled from the buisness logic as i would outsource the design work.
I was thinking of Ruby on Rails for this work as i have experience in the MVC model and RoR looks cool.I am from the mobility domain so i don't know whether RoR will suit my work
Would RoR suit this purpose.If yes where can i find the resources to the above mentioned requirements.
Thanks
Ruby on Rails would be ideal for this type of website.
Check out some of these resources for info on how to use Ruby on Rails:
http://guides.rubyonrails.org/
http://railscasts.com/
http://www.railsforum.com/
I noticed you are already aware of TeachMeToCode, but there is a tag there for all the Rails 3 tutorials, with some blog tutorials and what looks like the beginning of a series on how to build a del.icio.us clone. Since they are in Rails 3, they would be well worth checking out:
http://teachmetocode.com/screencasts/tag/rails-3/
One of the best tutorials:
http://railsforzombies.org
It will let you have your own point of view quickly.
It depends on with which languages you have experience. Any good MVC framework will do the job just fine but if you like Ruby syntax RoR is definitely a good framework to develop this kind of application.

How to use Rails or Ruby documentation?

I'm coming from C#, and recently I started to write some Ruby on Rails applications.
My biggest problem with it is the documentation because I find it extremly difficult to use. For example, finding out how to call generator from my controller took me about 2 hours and then 15 minutes after that I found Rails::Generators.invoke method to figure out what arguments should I pass to this function.
Maybe I use the documentation the wrong way; First I take a wild guess and search in the Netbeans code completion, which is rarely helpful, then I search in Google, then go with the API.
Can some experienced Rails programmer give me some advice?
If you're new to rails I recommend you read a book before you dive into the API documentation.
Here are two recommendations:
Agile Web Development With Rails - Great introduction and reference on how to use rails.
Programming Ruby 1.9: The Pragmatic Programmers' Guide - More on Ruby. Great references!
After you've worked your way through those books, you'll have an idea of how Rails is designed and where to look for stuff.
Both books are great reference books. If you want to access the Rails and Ruby API's online, make sure to checkout RailsApi.com
I am describing my own very personal workflow with Ruby/Rails documentation:
You can use ri and rdoc if you are familiar with the console, but...
Personally, I recommend two very good Ruby/Rails documentation sites:
apidock.com (no good search, but sometimes fine examples)
railsapi.com (very good AJAX search, plus you can customize what documentation you would like to see - by versions and by Gems)
Every iteration of the Rails guides (http://guides.rubyonrails.org/) has a ton of useful stuff in it. That should be the first stop.
After that I search away in the API - http://api.rubyonrails.org.
Sometimes I even end up just reading the source code trying to find things - https://github.com/rails/rails.
I think the best place in the source code to be reading is in here - https://github.com/rails/rails/tree/master/railties/lib/rails.
I upvoted each of the other answers here.

How to document a rails application?

I just started to document a rails application. I know this is actually done by rdoc, so I followed some rdoc guides regarding syntax and so on, but I got stuck when I tried to describe attributes of models, validations and the relationship between models, mostly because these things are part of ActiveRecord. So I wonder if there is some guide or a good practice regarding how to document a rails application or if there is something I'm missing?
I know that I could put all of this in the class description, but I wonder if there is a way more closely tied to the declaration itself (has_many, validates_presence_of, etc.) and what about the attributes?
I personally prefer YARD - http://yardoc.org , as it does a better job in documenting IMHO.
I don't know if there's a specific handler for Rails available, but it's quite easy to write one - http://yardoc.org/guides/extending-yard/writing-handlers.html
A good example might be the attribute handler - part of the yard gem:
lib/yard/handlers/ruby/attribute_handler.rb
Remember your tests are part of the documentation (for developers), particularly if you are using Cucumber where scenarios are easy to read. If you keep your methods very short and there is a test method with a descriptive name e.g. "should set the users name" I find I typically don't need comments on the method.
Validations or other parts of Rails I would not document. Part of being a Rails developer is understanding how these work, I think it is a fair assumption that another maintainer of your code reading it down the road will know validations, or other things built in to Rails. By that same logic, if you can use features of the framework or happy paths (not deviate much) with [documented] third party code, a lot of the documentation will be written for you.

Extracting a Rails application into a plugin or engine

I have a Rails 2.3 application which I would like to extract into a plugin, or engine. The application has user authentication, and basic cms capabilities supported by ancestry plugin.
I want to extract the logic for the application into a plugin/engine so that I can use this code for future projects, with a different "skin" or "theme" if required.
I'm not entirely sure I actually understand the difference between plugin and engine concepts, so that would be a good first point.
What is the best approach, are there any good starting points, links, explanations, examples that I should follow. Also, with the release of R3 to consider, is there anything that I should be aware of for that, with regards to plugins etc.
I am going to start off by watching Ryan's http://railscasts.com/episodes/149-rails-engines
but obviously thats over a year old now, so one of the challenges I'm faced with is finding the most up to date and relevant information on this subject.
All tips and help gratefully received.
Actually, converting an application is pretty straigtforward. Just create a plugin-folder, put an app-folder inside containing all yor model-views-controllers folders, and that's it.
You will have to manage your migrations yourself though. Also you have to define rake-tasks to copy files to your public folder. I think the railscasts is still pretty up-to-date, if anything it is now easier in rails 2.3.
Good luck!
[EDIT: for rails3] Rails 3 engines are very clean and powerful. Check this gist by Jose Valim.
You will probably be better off focusing your engine on Rails 3, as opposed to trying to make it compatible for Rails 2 and Rails 3, due to the backwards incompatible changes. Here is a more up to date tutorial for Rails 3
also the book "Crafting Rails applications" by Rails Core member Jose Valim, has a good chapter on it. Int he shows how to use his tool EngineX which generates a Rails 3 engine structure, so you can more easily create engines for your Rails 3 projects. His gem devise is also a rails engine which is also nice, because you can easily customize it by copying the templates into the application directory, and allowing you to subclass the controllers that you want to customize more.
Writing a plugin is an entirely different process than writing an app, if you already have your app code it should be straightforward converting it into a plugin.
Consider that if you use third-party plugins in your app it could get pretty messy.

Resources