This was a list of frequently asked questions for the Ruby on Rails: Talk mailing list and Google Group. The group is devoted to discussion of the Ruby on Rails ("Rails") web application framework. This is the list FAQ, and not affiliated with the Ruby on Rails core team, nor with any of the book and blog authors mentioned in the FAQ. The FAQ is maintained by Faisal N. Jawdat, with contributions from the rubyonrails-talk list members. If you have additional questions or answers you'd like to include, please mail them to faisal AT faisal DOT com.
What is the difference between Ruby and Rails?
Ruby is a general purpose programming language for scripting and other applications.
Rails is a web application framework written in Ruby, and is designed to make application development much faster than prior methods of building web applications. Rails does this by automating or simplifying the most common methods of solving the most common tasks in web application programming.
Why should I use Ruby?
If you are using Rails then you will need to use Ruby because Rails is written in and extensible using Ruby. If you have not yet decided to use Rails then you might elect to use a different web application framework based around a different language. These include MVC frameworks such as:
...and non-MVC tools such as:
Although Ruby has been getting a lot of attention due to Rails, Ruby predates Rails by almost 10 years and has been used for many scripting applications in that time. Many Ruby programmers prefer it over other languages because of its elegance. However, insofar as this list is devoted to the discussion of Rails, those arguments are rather irrelevant here.
What's good about Ruby?
Ruby is a powerful and expressive language. Ruby is a dynamically typed pure-OO language, and contains support for closures, continuations, and reflections. Most Rubyists find that they can write more compact code in Ruby than in other languages, and that the Ruby code is cleaner and easier to read and debug than in other languages. YMMV.
What is a good book about Rails?
True to its name, Ruby for Rails: Ruby Techniques for Rails Developers gives a more in depth coverage of the Ruby behind Rails, and how you can use it.
Can someone send me a PDF copy of AWDwR?
Short answer: No.
Long answer: The PDF is available for purchase online, and that PDF comes personalized with the name of the buyer. In addition, many if not all of the contributors to the book are on this list. Further, these authors are liked and respected for their contributions to the community. Finally, publicly asking someone you don't know to violate a copyright in a publicly available archived list isn't going to win you any friends here. Don't even ask.
Are there any good online references?
Is there a good editor for Rails?
In general, any programmer-friendly text editor should work, particularly any editor with support for Ruby and HTML, which is most of them.
Does Rails do AJAX?
Yes. Rails includes:
Rails AJAX development is trending towards pushing as much of the AJAX logic as possible into Ruby code so the programmer needs to go outside Ruby as little as possible. YMMV.
Mail seems out of order. How can we fix it?
The list uses Google Groups, which is occasionally unreliable. In general, the mail comes through eventually. So far this hasn't been a problem.
Why is all this spam coming through?
Google Groups does not have 100% effective spam prevention mechanisms. The list maintainers attempt to remove spam from the online archive -- and remove the spammers from the list -- as spam is noticed, but this, too, is not 100% effective. You may wish to look into getting a spam filter for your client.
Is there a Ruby or Rails group in ...?
How do I install Rails?
See the core site's instructions here.
How can I create a self-referential has_many :through association?
See Josh Susser's description here.
Why do I need to write all these tests?
You don't need to, but it's probably a good idea if you want your code to actually work. There is a technical answer and a philosophical reasons to test with Ruby (and, by implication, Rails).
The technical answer is that Ruby, like all dynamic languages, does more at runtime and less at compile time. Accordingly, the compiler won't catch a lot of the sorts of things that Java and C#'s compilers would. However, a test suite that exercises much of your code will tend to catch those problems.
The philosophical answer is that the Rails community tends to favor Agile methods of software development, and Agile methods tend to favor test-heavy (often test-first or test driven) programming practices due to their flexibility.
In any case, Rails comes with a built in testing framework, and Rails developers tend to use the framework heavily.
How do I get a Rails app to start at startup on a Mac OS X system?
The answer to this depends on what platform you're using to deploy Rails. For most things, you'll need to use launchd, or a StartupItem. launchd is Apple's prefered method, and StartupItems are going away, although StartupItems are often a better fit for many UNIX daemons.
However, if you're using the built-in Apache 1.3 setup with fcgi, you can just start Apache from the Sharing pane in System Preferences.
Where can I host Rails apps
Anywhere you have total control of your host. In addition, many hosting providers are starting to provide Rails support. That said, running Rails in production can be tricky, and hosting providers are still developing competency in this area. Further, the environment they offer may be out of sync with the version of Rails that you require. There is no simple answer here, and it pays to do your homework before spending money.
How should I set up web servers for running in production?
The answer to this question is still open, and your answer will depend in large part with what server software you are required to use, what performance constraints you have, and how much tolerance you have for bleeding-edge code. As of summery, 2007 it appears the favored setup involves one or more instances of Apache with mod_proxy_core, or a load-balancing proxy server, speaking to multiple (possibly distributed) instances of Mongrel running Rails.
How can I best deploy releases of my app?
Ruby is slow! (Ruby uses a lot of memory, Rails is not threaded, etc.)
(Yes, that wasn't a question, but the topic comes up enough to merit an entry.)
Ruby is slower than many other programming languages for similar applications, both in general (more instructions and resources required to get the same work done) and specific (non-native threads, etc.) That said, many Rubyists find that the cost in execution speed is made up for in programmer happiness and productivity, and that these improvements make it easier for Ruby programmers to optimize their code more effectively. A couple projects exist to speed up the Ruby interpreter, but they're a few years out at best.
Ruby's performance is less of an issue for Rails. Rails deployment is typically fairly distributed, and the main performance bottleneck is usually somewhere other than Ruby itself (e.g. database load). Rails developers typically uses approaches like Memcached to boost real-world performance where needed. Understanding where the bottlenecks live is important.
How many users/requests/sessions can [some config] handle?
This is impossible to answer without testing the exact config with behavior closely resembling that of real users and your real application's real code. While list members may throw out some ballpark numbers, their answers depend on their configs and thus should be treated with skepticism.
How do I test an action that requires a user to be logged in?
It depends on how you're doing authentication. If you're using acts_as_authenticated, then `include AuthenticatedTestHelper` and `login_as :user_name_here`. If you're using some other method then you'll need to somehow fake out the system (e.g. manually populate the session). See this thread for more.
What does this Ruby code mean?
foo ? bar : baz
How do I enforce foreign key constraints in the db?
Rails does not have built in support, but you can add the constraint manually in a migration using the execute statement. RedHill Consulting has also created two plugins to add support FK constraints to Rails.
How do I test views? view helpers? migrations?
To test views you will need to use assert_select. AWDwR has more documentation on the method, and Assaf Arkin put together a useful cheat sheet on the method. To test helpers use Geoffrey Grosenbach's helper_test plugin. To test migrations see Atomic Object's migration_test_helper plugin.
Why is pagination not working?
Pagination is tricky to get right. An important step is to not use the built-in pagination code, but use a plugin instead. See Mike Garey's explanation, and discussion.
How can I debug a rails app?
First, use tests to catch predictable bugs early. Second, look in the app's logs (in the log/ dir) to find stack traces after exceptions are raised. If you need a debugger, use rdebug. IDEs like RadRails and Netbeans have interfaces on top of rdebug, for visual step debugging.