Notes posted by neves
RSS feed
Turn layout off with render
Thats awkward, but the code below does not turn layout off:
render :action => "short_goal", :layout => nil
you must use false
render :action => "short_goal", :layout => false

Brazilian Real (R$ 1.200,95)
helper:
def number_to_currency_br(number) number_to_currency(number, :unit => "R$ ", :separator => ",", :delimiter => ".") end

%w(true false) != [true, false]
Don´t confuse the right:
validates_inclusion_of :published, :in => [true, false]
with the wrong:
validates_inclusion_of :published, :in => %w(true false)
cause:
%w(true false) == ["true", "false"]

script/generate syntax
To add a post_id field to a comments table, run this:
script\generate migration add_post_id_to_comment post_id:integer
See that it´s not the table name(plural), but the model name(singular),<br /> and post_id:references, does not works like in create_table.
This is the generated migration:
class AddPostIdToComment < ActiveRecord::Migration def self.up add_column :comments, :post_id, :integer end def self.down remove_column :comments, :post_id end end

with password md5 encrypted
If you are afraid to let your plain password on the code, you can do this instead:
require 'digest' class AdminController < ApplicationController before_filter :authenticate def authenticate authenticate_or_request_with_http_basic('Administration') do |username, password| md5_of_password = Digest::MD5.hexdigest(password) username == 'admin' && md5_of_password == '5ebe2294ecd0e0f08eab7690d2a6ee69' end end end
where ‘5ebe2294ecd0e0f08eab7690d2a6ee69’ is the md5 of the word ‘secret’.
You can get your own with this free webservice: <br /> http://qi64.appspot.com/md5/secret (replace ‘secret’ with your secret word).

end_year
date_select supports end_year, too.
date_select("user", "birthday", :start_year => 1940, :end_year => Date.current.year - 13)

initializers
initializers/* are not loaded if one of the required gems fails to load. So your inflections, mines, etc, will not be loaded.
The required gems are defined on environment.rb with config.gem