Notes posted by zoopzoop
RSS feedHighlight keywords in a text
Case-insensitive
keywords.inject(text) { |text, keyword| text.gsub(/(#{keyword})/i, "<strong>\\1</strong>") }
<strong> can be replace by whatever HTML tag you want for hightlighting (<b>, <i>, …)
Valid options changed in Rails v2.3.0 RC1
The valid options in Rails v2.3.0 RC1 are no longer
:connector and :skip_last_comma, but
:words_connector, :two_words_connector, and :last_word_connector:
>> %w(lorem ipsum dolor sit).to_sentence => "lorem, ipsum, dolor, and sit" >> %w(lorem ipsum dolor sit).to_sentence(:words_connector => ' + ') => "lorem + ipsum + dolor, and sit" >> %w(lorem ipsum).to_sentence(:two_words_connector => ' through ') => "lorem through ipsum" # No effect if more than two words >> %w(lorem ipsum dolor sit).to_sentence(:two_words_connector => ' through ') => "lorem, ipsum, dolor, and sit" >> %w(lorem ipsum dolor sit).to_sentence(:last_word_connector => ' or ') => "lorem, ipsum, dolor or sit"
Check if value is included in array of valid values
If you want to check the value of an attribute using an array of valid values, the array has to be defined before the validation, so
validates_inclusion_of :name, :in => VALID_NAMES VALID_NAMES = %w(Peter Paul Mary)
won’t work, but
VALID_NAMES = %w(Peter Paul Mary) validates_inclusion_of :name, :in => VALID_NAMES
will.
Opening a link in a new window
Use “_blank”, not “_new” to open a link in a new window.
link_to "External link", "http://foo.bar", :target => "_blank" # => <a href="http://foo.bar" target="_blank">External link</a>