Notes posted by ronald
RSS feed
for rails >= 3
template_root= is deprecated, use prepend_view_path instead
source: ActionMailer/DeprecatedApi/ClassMethods/template_root

relative_url_root= no longer exists in Rails 3.0
Rails 3.0 does this with scope in config/routes.rb
scope "/exampleapp" do resources :examples root :to => "examples#index" end

config/environments/production.rb
old
ActionController::AbstractRequest.relative_url_root= "/exampleapp"
new
config.action_controller.relative_url_root= "/exampleapp"

list of predefined variables
$! The exception information message set by ‘raise’. $@ Array of backtrace of the last exception thrown.
$& The string matched by the last successful pattern match in this scope. $` The string to the left of the last successful match. $‘ The string to the right of the last successful match. $+ The last bracket matched by the last successful match. $1 to $9 The Nth group of the last successful regexp match. $~ The information about the last match in the current scope.
$= The flag for case insensitive, nil by default. $/ The input record separator, newline by default. $\ The output record separator for the print and IO#write. Default is nil. $, The output field separator for the print and Array#join. $; The default separator for String#split.
$. The current input line number of the last file that was read. $< The virtual concatenation file of the files given on command line. $> The default output for print, printf. $stdout by default. $_ The last input line of string by gets or readline.
$0 Contains the name of the script being executed. May be assignable. $* Command line arguments given for the script sans args. $$ The process number of the Ruby running this script. $? The status of the last executed child process. $: Load path for scripts and binary modules by load or require.
$“ The array contains the module names loaded by require. $DEBUG The status of the -d switch. $FILENAME Current input file from $<. Same as $<.filename. $LOAD_PATH The alias to the $:. $stderr The current standard error output. $stdin The current standard input. $stdout The current standard output. $VERBOSE The verbose flag, which is set by the -v switch. $-0 The alias to $/. $-a True if option -a (”autosplit“ mode) is set. Read-only variable. $-d The alias to $DEBUG. $-F The alias to $;. $-i If in-place-edit mode is set, this variable holds the extension, otherwise nil. $-I The alias to $:. $-l True if option -l is set (”line-ending processing“ is on). Read-only variable. $-p True if option -p is set (”loop“ mode is on). Read-only variable. $-v The alias to $VERBOSE. $-w True if option -w is set.
Source: http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Variables_and_Constants#Pre-defined_Variables


multiple filter example
actually you can have it even shorter with:
before_filter :authorize, :set_locale, :except => :login



usage helper with block
helper example
def my_helper(&block) inner = capture(&block) out = "<somehtml>#{inner}</somehtml>" block_called_from_erb?(block) ? concat(out) : out end
view example
<% my_helper do %> sometext <% end %>
output
<somehtml>sometext</somehtml>

alternative
not sure but block_called_from_erb? seems to be the replacement



Examples
see have_at_least or have

usage example
code
class MyModel < ActiveRecord::Base def created_today? self.created_on.to_date == Date.today end end


two ways to disable single table inheritance
-
Don’t use the column name ‘type’
-
Or if the first is no option for you: Tell Rails to look for a not existing column like:
class MyModel < ActiveRecord::Base
# disable STI inheritance_column = :_type_disabled end

alternative (working with 2.2.X)
ActionController::Base.relative_url_root