Flowdock

Notes posted by foliosus

RSS feed
August 19, 2012
0 thanks

On destroying data

Reply to tvle83 and pgmcgee: the destructiveness of this method depends on your database. Some databases are better at converting between disparate types than others. For example, when changing a column from a numeric type to a string type, some databases drop the data where others will turn the numbers into their string representations.

Essentially, YMMV.

November 12, 2011 - (<= v2.3.8)
0 thanks

Specify attachment names

If you want to give your attachment a name, you can do this:

attachment :filename => 'my_file.txt', :body => File.read('/var/null')

It will appear to the recipient as a file named “my_file.txt” rather than something awful like “noname 1”.

January 18, 2011
2 thanks

Common AJAX options

See the documentation for link_to_remote to see the common AJAX options, like :before and :completed.

October 19, 2010
1 thank

Looking for the docs?

Check the ClassMethods – the docs on filters are there.

November 16, 2009
3 thanks
April 3, 2009
13 thanks

The docs are in AR::Base

The docs you’re looking for are in ActiveRecord::Base

March 21, 2009
7 thanks

Use helpers in your ActionMailer views

It’s very easy to give your mailer access to helpers:

# Let your mailer user the ApplicationHelper methods
class MyMailer < ActionMailer::Base
  helper :application
end
March 20, 2009
9 thanks

Use the current URL, with changes

You can use the current URL, whatever it is, with changes, as in:

# Create a link to the current page in RSS form
url_for(:overwrite_params => {:format => :rss})

This can be super-helpful because it preserves any GET params (like search parameters)

February 23, 2009 - (<= v2.2.1)
1 thank

You can't have many :through with habtm

Imagine the following

a has_many b
b has_and_belongs_to_many c
a has_many c :through => b

a.b works fine

b.c works fine

a.c throws an error!

has_many :through where the through association is a habtm is not supported in Rails. The error is:

ActiveRecord::HasManyThroughSourceAssociationMacroError: Invalid source reflection macro :has_and_belongs_to_many for has_many :stories, :through => :subcategories. Use :source to specify the source reflection

Specifying the source reflection still won’t help you though, because this kind of has_many :through isn’t supported at all.