Good code sample in rails - ruby-on-rails

I have been developing in rails for the past 1.5 years .. however , I feel my code is not upto the mark , and I still dont fully utilize all that Ruby and Rails have to offer .
I have gone through all the material that is available on the guide site , and have incorporated that in my code . However , every time I see someone else's code , I find out new things about the language like idiomatic syntax etc . I was wondering if there are some really good code samples of rails that people can refer which would help me speed up my progress in rails . It can be anything , like some open source plugin or a app that has really high code standards .

You can start from GitHub. There are tons of Rails plugins and apps available.
Here's just a few examples:
GemCutter
Spree
Fat Free CMS
Insoshi
Plugin authors
Thoughtbot
Ryan Bates
Bynarylogic
Joshua Peek

My favorite and commonly used gem/ Rails plugin is will_paginate. Pagination is pretty common in any web applications.
will_paginate is hosted on GitHub. It works as a standard gem.
If you want to learn about Rails plugin development including how to read the code, you might want to read Plugin Patterns in Rails 2.

Have a look at Mephisto, a blogging platform written in Rails: http://mephistoblog.com/

Related

Ruby on Rails Quickstart

I've just completed a couple of Ruby on Rails books which were excellent. I'd like to know if there are any quickstarts or guides that can serve to jumpstart to my RoR projects but without all of the explanations that I have search through to get the steps. Thanks in advance.
Don't understand since you have read a couple of books and guides, why you would still need a quickstart guide to develop your own app. Rather contradicting. Why don't you just start developing an app from scratch with your awesome idea?
Anyway, to answer your question, try Michael Hartl's Rails Tutorial to build a Twitter app.
Good luck!
(Caveats: I'm too new to post many links so you may need to copy/paste. Not all of these are for the most current versions of Ruby/Rails but they will certainly get you going.)
CLONE TUTORIALS
Twitter Clone
railsforzombies.org
Pinterest Clone
guides.railsgirls.com/app/
Good Reads Clone
zero-to-sixty-creating-and-deploying-a-rails-app-in-under-an-hour
(You will need to do some things differently in Rails 3/4 and just skip the Authlogic stuff altogether.)
GENERAL STARTS
Ruby Guide
getting_started.html (also noted above)
Sitepoint Tutorial
building-your-first-rails-application-models
STARTER APPLICATIONS
Bort
github.com/MattHall/bort/tree/master
BaseApp2
github.com/dannymcc/BaseApp2 (requires QT SDK # qt-project.org)
Boilerplate
github.com/npverni/rails-boilerplate-script
SPECIFIC USE STARTER APPS
Community Engine
communityengine.org
Tog
toghq.com
Open Source Rails
opensourcerails.com (Library of apps; build on the shoulders of giants, geniuses/genii, and semi-talented braggarts)
How about this one?
http://guides.rubyonrails.org/getting_started.html
If you read Ruby on Rails Tutorial: Learn Rails by Example then you should be good to go. If not you could go through that book it is free online here.

Well built rails code for download

I want to get into rails by examining well built code
where can i find typical open source rails project that i can download
and learn from ?
i'm interested in facebook connect integration (facebooker), tag clouds, searching in
my website
I'm not looking not tutorials or screen casts
Thanks!
This question gives a good list
a list of projects with good test-suites
a list of open source rails apps to learn from
Have a browse of ruby tool box and download some open source. For example there's refinery and zena, two content management systems and Rboard, a forum. Depends what you want really but there's plenty out there. Ruby toolbox entries are ordered by github watchers and forks to give you an idea of their popularity.
I really like looking at the commits in teambox.
I find it a bit more complicated. But there's also spree.
There's also devise which is really interesting to look at too.
Finally, I'd recommend you to follow the rails commits (it's the only commits feed I have in my Google Reader).
Gady, this is an extremely rich topic you're asking about and resources are all over the internet. Try starting at http://rubyonrails.org/.
You should be able to find tens of questions just like yours (asked and answered) by searching SO at the top bar.
For Rails, part of it is the building process, so one feasible approach is to read a tutorial like http://railstutorial.org/book
then when in Chapter 2, you will use Scaffold, and at that time, you will have some basic code to look into how a basic Rails app is.
I also suggest you use source control like Git, Mercurial, or SVN to commit different phases of the project, from creating the rails project and then after each step, so you can diff what the changes are during each step.
If you already have Ruby 1.9.2, Rails 3.0.1, and sqlite3, then you can
rails new myproj
cd myproj
rails generate scaffold foo name:string salary:integer gpa:float note:text
rake db:migrate
rails server
and now you can use http://localhost:3000/foos to create, display, update, delete the foo records, and have quite a bit of source code to look at. Most of the customizable code is in app, with css and javascript in the public folder.
Ryan Bates has an excellent series of videos.
http://railscasts.com/
An extremely valuable resource.
Radiant is a CMS that you can download for free and see how it works. It is a great piece of code to look at and see how it works.
I guess that most open source Rails projects are shared on Github, so it may be interesting to browse its Ruby section and look for most watched or most forked projects:
http://github.com/languages/Ruby
Steady stream of new interesting projects to take a look at :)
And don't forget the official:
guides.rubyonrails.org
well there is one "bigger" project on github, waiting for downloading and contribution...
but it's a little controversial because of the security issued they have (had?)
It's still worth a look:
http://github.com/diaspora/diaspora

Compiling / building ruby online from a working rails application

I'm totally new to Ruby but not to programming. All I did was going through try ruby and reading differences from other few languages I know better (mostly PHP and some Python). So I have no idea how Rails differ from Ruby and maybe this is an absurd question.
Anyways...
I don't want (or am able) to install Ruby on my machine and I'd still like to build a single working source file. Is it possible to have an online compiler of some sort? If so, how?
If I write a Rails web site (comprised of either one or many files) using any given host (that far I know I can), would I be able to use that same code with very minor modifications and just run as a Ruby app? Again, how?
(new) What about the other way around: a Ruby app turning into a Rails web page? Easy to do?
I really hope for a "yes" on them all, but I doubt on the 1st and not so much on the last. :)
There are online "IDEs" you can use to try out ruby:
http://ideone.com
http://codepad.org
But mind you that Ruby on Rails is a framework written in Ruby and those sites don't have RoR installed. Also note you that a Rails app has many, many files.
If you have the same code and same server configuration (version of ruby, database, plugins, etc.) you should only need minor modifications to the config file.
Ruby on Rails is on Ruby. So whatever works on Ruby should work just fine on RoR with minor modifications. However, you'll probably want to rewrite the app to take advantage of many of the features RoR provides.

Is Ruby on Rails suitable for a non-web application?

I am interested in developing a workstation-based application that communicates with a proprietary data server and that presents information from that server to the user. I am not intending the user interface to be browser-based, and have been considering Qt as my framework. Should I consider RoR for this? Thanks.
Rails is specifically a web application framework, however there are GUI toolkits that can be used with Ruby, including Qt (although not the open source version).
Rails is a web framework, so you should not use it. However, you should absolutely consider using Ruby. I've never used Ruby with Qt, but I've had a lot of success using JRuby with Swing. I use the Profligacy gem, which suits my needs quite well.
Being a web framework you may not use rails, but you may certainly use some parts of rails.
For example just use require 'active_record' and you instantly have access to AR and all its magic - validations, belongs_to, has_many and other similar associations.
You can use the ActiveRecord part of Ruby on Rails, which for a long time was the most interesting part of RoR. https://edgeguides.rubyonrails.org/active_record_basics.html
Alternatively, use another Ruby ORM, like DataMapper: http://datamapper.org/
The answer is yes. I've been working on a project, Qt on Rails, which combines Qt with a Rails back end. The end result is that you can develop your Qt app's in Ruby, harness the libraries of Rails and there's support for scaffolding of apps as well.
It’s still a 'Work In Progress' but the current latest version at the Qt on Rails github repository (http://github.com/theirishpenguin/qtonrails) will certainly give a flavour of where the project is headed. Contributors and feedback is most welcome and detailed blog post is available on the project.

Coming back to Rails

So I've decided after a few years away, that I want to get back into Ruby on Rails for some of my personal projects. What I'm wondering is what are the best resources to find out what the new features are in rails? I haven't really even touched Rails since 1.2 was new.
Oh yeah, and is TextMate still the defacto editor for RoR on the Mac, or has something better come along?
Check out the official Rails Guides. These should provide a nice overview of Rails (if you are rusty) and are kept up-to-date with the latest versions.
You may want to check out Ryan Daigle's Edge Rails posts which covered features as they were added to the new versions. Use the dates to determine where to start and go through each one. He also has a PDF for $9 which covers upgrading to Rails 2.1.
I have also covered the changes on Railscasts. Check out the various tags for each version to see them: 2.0, 2.1, 2.2, 2.3.
Update: Thoughtbot blog has posted about upgrading to Rails 2.1 and 2.3.2.
I found the book Agile Web Development With Rails (3rd edition) to be the most helpful to get me going again earlier this year. In particular it notes some concepts that have changed as well as introducing the new items.
Regarding editing, Textmate still seems to be #1 among the MacRails folks, the text-editing ones, at least.
Beyond that, there are some IDEs around now, if that's your preference. They're starting to become fairly not-awful, which is pretty impressive really. There are plenty of questions here that touch on the topic: try searching for "ruby rails ide"
The Ruby Toolbox is a great and fairly new resource for seeing what gems/plugins/tools are popular for various aspects of your application such as authentication, testing frameworks, search, etc. It's based on the number of watchers and forks each project has on GitHub, which is a reasonably good way of judging popularity.
As for a newer editor ...
I have found that sublime text is a great editor for ruby and rails projects, it has great syntax highlighting out of the box, Vim keybindings available (vintage mode), a sweet package system to add functionality for other languages like SASS or Coffeescript and an excellent file browser that helps with complex folder structure that can happen in a rails project.
Also, it is highly extendible and configurable, I switched to it from Vim.
http://www.sublimetext.com/

Resources