% ul_needed = true %> <% if not defined?(parent_class) %> <% # we didn't come here via _show.html.erb %> <% if @parent_class.nil? %> <% # the controller didn't give us a parent_class, this means we are here for the 'first' time %> <% # we have to rely on the @Klass set in the controller %> <% update_span = @Klass.to_s.pluralize.downcase + '_list' %> <% path_to_new = "new_#{@Klass.to_s.singularize.underscore}_path" %> <% parent_class = nil %> <% parent_id = nil %> <% objects = @objects %> <% model = @Klass %> <% else %> <% # the controller gave us an @parent_class, so ... %> <% attribute = @Klass.to_s.underscore.pluralize %> <% update_span = "#{@parent_class.to_s.underscore}_#{@parent_id}_#{attribute}_list" -%> <% path_to_new='new_' + attribute.to_s.underscore.singularize + '_path' %> <% parent_class=@parent_class.constantize %> <% parent_id=@parent_id %> <% objects = @objects %> <% ul_needed = false unless @ul_needed %> <% model = attribute.to_s.singularize.camelcase.constantize %> <% end %> <% else %> <% # here we come from _show %> <% update_span = "#{parent_class.to_s.underscore}_#{parent_id}_#{attribute}_list" -%> <% path_to_new='new_' + attribute.to_s.singularize + '_path' %> <% foreign_key = parent_class.reflect_on_association(attribute.to_sym).options[:foreign_key] || parent_class.name.foreign_key -%> <% model = attribute.to_s.singularize.camelcase.constantize %> <% conditions = [ "#{model.table_name}.#{foreign_key} = ?", parent_id ] %> <% objects = parent_class.find(parent_id).send(attribute) %> <% objects = parent_class.find(parent_id).send(attribute).accessible_by(current_ability) if cancan_enabled? %> <% objects = objects.order(attribute.to_s.singularize.camelcase.constantize.order_by_clause) if attribute.to_s.singularize.camelcase.constantize.respond_to?(:order_by_clause) && ! attribute.to_s.singularize.camelcase.constantize.order_by_clause.nil? %> <% objects = objects.paginate :page => params[:page], :per_page => @PER_PAGE || 5, :conditions => conditions %> <% end %> <%= raw "