Make sure your action names don't step on any toes.

jmcnevin Jun 1, 2009 2 thanks

In my experience, if you ever have a controller action named "process", your controller will cease to function, as there is both a class and instance method called process in ActionController::Base.

There are undoubtedly other action names that will cause conflicts, but this one is particular I've...

Potentially slow operation

szeryf May 27, 2009

Remember that checking for a value is a potentially slow operation (all the elements might be iterated) as oposed to querying a key (e.g. with has_key?), which is supposed to be fast in a Hash.

map_with_index

rob-twf May 26, 2009 3 thanks

If you want to access the element index when using map, you can do it with enum_for:

(1..6).enum_for(:each_with_index).map { |v, i| "index: #{i} value: #{v}" } #=> ["index: 0 value: 1", "index: 1 value: 2", "index: 2 value: 3", "index: 3 value: 4", "index: 4 value: 5", "index: 5 value: 6"]

Potentially slow operation

szeryf May 26, 2009 1 thank

Remember that checking for a value is a potentially slow operation (all the elements might be iterated) as oposed to querying a key (e.g. with has_key?), which is supposed to be fast in a Hash.

Symbol Keys Only

tadman May 20, 2009

While OpenStruct#new is rather indifferent to the kind of keys submitted, marshal_load requires Symbol keys only. Use of a string can cause difficulty.

To fix:

marshal_load(hash.inject({ }) { |h, (k,v)| h[k.to_sym] = v; h })

As a note, Rails has the Hash#symbolize_keys method that can be used...

How to set request parameters

weibel May 19, 2009 2 thanks

On previous versions of TestRequest it was possible to set the request_parameters on the new action. This option is now gone, but it's still possible to set the parameters after initialization.

==== Code example

request = ActionController::TestRequest.new request.env["action_controller.request....

Using gmail SMTP server to send mail

morgoth May 8, 2009 2 thanks

If you're running Rails >= 2.2.1 [RC2] and Ruby 1.8.7, you don't need plugin below. Ruby 1.8.7 supports SMTP TLS and Rails 2.2.1 ships with an option to enable it if you're running Ruby 1.8.7.

All You need to do is:

ActionMailer::Base.smtp_settings = { :enable_starttls_auto => true }