Frequently Asked Questions

Q. How do I reference the controller/action name within a controller/view?

A. params[:controller] or params[:action]. If you have a namespaced controller it will print out like namespace/controller.

Q. I’m getting undefined method scaffold. I’ve just upgraded to Rails 2.

A. http://tpope.us/rubyonrailsfaq.html

Q. I’m getting undefined method start_form_tag. I’ve just upgraded to Rails 2.

A. start_form_tag has been deprecated as of Rails 2.0. The correct syntax is to now use a block:

<% form_for @object do |f| %>
  <%= render :partial => "form", :locals => { :f => f } %>
  <%= f.submit "Create" %>
<% end %>>

Alternatively, use form_tag and specify a :controller and :action parameter if necessary.

Q. What are these .html.erb files my application is generating? What happened to .rhtml?

.rhtml has been dropped in favour of .html.erb because it is more readable and allows you to easily define formats. The correct extension now is [format].[template] or in this example: html.erb.

Q. [Insert non rubyonrails related question here]

A. If you’re asking an apache question, go to #apache. If you’re asking a PHP question, go to ##php. If you’re asking a MySQL question, go to #mysql. If you’re asking a PostgreSQL question, go to #postgresql.

Q. What’s a good captcha plugin? You can use either simple_captcha or ReCAPTCHA, both of which are excellent plugins.

Q. I’m getting undefined method `association’ for #<Class:0x24acbb0>

You’re most likely trying to call a method on an association. Say you have three models: Post, Comment & User. Post has many comments, comments belongs to post, comment belongs to user and user has many posts and comments. When you try to get all the users for all the comments on a post, say @post.comments.user you will get the above error.

The correct way to do this is @post.comments.map { |comment| comment.user }.flatten or @post.comments.map(&:user).flatten.

Q. Ruby / Ruby on Rails doesn’t scale!

A. Yellow Pages and Twitter are two sites that are both using Ruby on Rails. Ruby scales just like every other language.

Q. [insert dumb question here]

A. Sometimes your question may be deemed one that could be answered by having a greater grasp of Ruby or Rails. To do this, go off and read a book or the guides and then try to tackle your problem again. Nothing worse than trying to solve a problem with no idea.

Q. What is the best authentication system out there?

A. A favourite amongst Rails developers is restfulauthentication which offers a very large majority of functionality people look for in authentication systems. If you don’t require a section of functionality from restfulauthentication it is very easy to strip out.

Q. How do I add actions to my RESTful controllers?

A. http://guides.rails.info/routingoutsidein.html#addingmorerestfulactions

Q. I’m trying to do [thing]. I am using Windows.

A. Ruby on Rails development was made for UNIX based systems and sometimes requires you to compile things. It is recommended that you do not develop on Windows-based systems.

Q. When I click on the link for “About your application’s environment” it gives me an error that it cant find public/rails/info/properties

A. Try accessing it from localhost, such as http://localhost:3000. Accessing it through apache may still give you this error.

Q. Should I use FastCGI, nginx or Apache (Passenger?)

A. FastCGI is old and outdated and not a recommended way to deploy Rails applications.

What is recommended however is that you use something like nginx + mongrel_cluster or apache with passenger.

Q. I am using an older version of rubygems, how do I update?

A. Type sudo gem update –system or gem update –system

Q. With ActiveMerchant and Paypal, is there a way to redirect to PayPal’s sandbox instead of going to production?

A. Put ActiveMerchant::Billing::Base.mode = :test in your config/environment.rb file.

Q. Why can I not assign values to a field called type in my table?

A. By default, the type field is reserved for Single Table Inheritance (STI) in Rails and therefore you won’t be able to assign values to it. To get around this, add self.inheritance_column = nil inside the model’s class definition.

Q. How do I test SSL on my Rails application (Apache)?

A. Best solution for this is to follow this guide and set it up for your app that way.

Q. What are good hosts for Ruby on Rails applications?

A. Generally the consensus is Slicehost and Linode. There’s also Heroku and The Bluebox Group and many more. Shop around and find out what’s best for you, remembering what’s best for someone else may not be for you.