lib/scaffolding_extensions/meta_controller.rb
# Create action for returning results from the scaffold autocompleter
# for the given model.  If an association is given, allows autocompleting for
# objects in an association.
Create action for returning results from the scaffold autocompleter
for the given model.  If an association is given, allows autocompleting for
objects in an association.
Create action for returning results from the scaffold autocompleter for the given model . If an association is given allows autocompleting for objects in an association .
def scaffold_auto_complete_for(klass, association=nil)
        meth = "scaffold_auto_complete_for_#{klass.scaffold_name}"
        (self.scaffolded_auto_complete_associations[klass] ||= Set.new).add(association.to_s)
        allowed_associations = scaffolded_auto_complete_associations[klass]
        unless instance_methods.include?(meth)
          scaffold_define_method(meth) do
            association = scaffold_request_param(:association).to_s
            if scaffold_request_param(:association) && !allowed_associations.include?(association)
              scaffold_method_not_allowed
            else
              @items = klass.scaffold_auto_complete_find((scaffold_request_id || scaffold_request_param(:q)).to_s, :association=>(association.to_sym if scaffold_request_param(:association)), :session=>scaffold_session)
              scaffold_render_template(meth, {}, :inline => "<%= scaffold_auto_complete_result(@items) %>")
            end
          end
        end
      end
def scaffold_auto_complete_for ( klass , association = nil ) meth = "scaffold_auto_complete_for_#{klass.scaffold_name}" ( self . scaffolded_auto_complete_associations [ klass ] ||= Set . new ) . add ( association . to_s ) allowed_associations = scaffolded_auto_complete_associations [ klass ] unless instance_methods . include? ( meth ) scaffold_define_method ( meth ) do association = scaffold_request_param ( :association ) . to_s if scaffold_request_param ( :association ) && ! allowed_associations . include? ( association ) scaffold_method_not_allowed else @items = klass . scaffold_auto_complete_find ( ( scaffold_request_id || scaffold_request_param ( :q ) ) . to_s , :association => ( association . to_sym if scaffold_request_param ( :association ) ) , :session => scaffold_session ) scaffold_render_template ( meth , { } , :inline => "<%= scaffold_auto_complete_result(@items) %>" ) end end end end
Create action for returning results from the scaffold autocompleter
for the given model.
Create action for returning results from the scaffold autocompleter for the given model .
# Prototype uses the request id, JQuery-Autocomplete uses the q parameter
klass
<not_specific>
association
<not_specific>