What's new? | Help | Directory | Sign in
Google
activescaffold
A Ruby on Rails plugin that creates dynamic user interfaces for your models
  
  
  
  
    
Search
for
Updated Apr 04, 2007 by edwin.moss
Labels: Type-Howto
HowToOverrideMethodFormBelongsToAssociation  

How to override by method the form field of a :belongs_to association column

In Controller:
    config.columns[:#{column_name}].ui_type = :select


In Helper:

  def options_filtered_by(value)
    Model.find(:all, 
        :conditions => [ "value >= ?", value ], :order => "last_name ASC, first_name ASC").collect { |u| [ last_name[0..20], u.id ] }
  end

  def #{column_name}_form_column(record, input_name)
    selected_id = record.#{column_name}.id unless record.#{column_name}.nil?
    select(:record, :#{column_name}, options_filtered_by(:some_value), { :selected => selected_id }, { :name => input_name + "[id]" })
  end

Sign in to add a comment