Skip to content

Instantly share code, notes, and snippets.

View liangzan's full-sized avatar

Wong Liang Zan liangzan

View GitHub Profile
# lib/formtastic.rb
def find_collection_for_column(column, options)
collection = find_raw_collection_for_column(column, options)
...
end
# lib/formtastic.rb
def find_raw_collection_for_column(column, options) #:nodoc:
collection = if options[:collection]
options.delete(:collection)
elsif reflection = self.reflection_for(column)
options[:find_options] ||= {}
if conditions = reflection.options[:conditions]
options[:find_options][:conditions] = reflection.klass.merge_conditions(conditions, options[:find_options][:conditions])
end
reflection.klass.find(:all, options[:find_options])
def select_input(method, options)
...
collection = find_collection_for_column(method, options)
self.select(input_name, collection, strip_formtastic_options(options), html_options)
...
end
Player.find(:all) # retrieves all the players
reflection = self.reflection_for(column) # returns a Reflection object.
reflection.klass # retrieves the Player class in our case
reflection.klass.find(:all, options[:find_options]) # equivalent to Player.find(:all, options[:find_options])
# lib/formtastic.rb
def localized_string(key, value, type, options = {}) #:nodoc:
key = value if value.is_a?(::Symbol)
if value.is_a?(::String)
value
else
use_i18n = value.nil? ? @@i18n_lookups_by_default : (value != false)
if use_i18n
model_name, nested_model_name = normalize_model_name(self.model_name.underscore)
action_name = template.params[:action].to_s rescue ''
def localized_string(key, value, type, options = {})
# lib/formtastic/i18n.rb
SCOPES = [
'{{model}}.{{nested_model}}.{{action}}.{{attribute}}',
'{{model}}.{{action}}.{{attribute}}',
'{{model}}.{{nested_model}}.{{attribute}}',
'{{model}}.{{attribute}}',
'{{nested_model}}.{{attribute}}',
'{{attribute}}'
]