<% 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 "
" if ul_needed -%> <% for object in objects %> <% if parent_class.nil? %> <% css_class_id = object.class.to_s.underscore + '_' + object.id.to_s -%> <% path_to_object = object.class.to_s.underscore + '_path' %> <% else %> <% css_class_id = parent_class.to_s.underscore + '_' + parent_id.to_s + '_' + attribute.to_s.singularize.underscore + "_" + object.id.to_s -%> <% path_to_object = attribute.to_s.singularize.underscore + "_path" %> <% end %>
<%= link_to_destroy(object, css_class_id) -%>
<%= link_to h(object._presentation), send( path_to_object, object, :update => css_class_id), :remote => true -%>
<% end -%> <% if parent_id.nil? -%> <% pagination = will_paginate objects -%> <% else %> <% pagination = will_paginate objects, :remote => true, :params => {:controller => attribute, :action => :index, :id => nil, :parent_class => parent_class, :parent_id => parent_id, :update => "#{parent_class.to_s.underscore}_#{parent_id}_#{attribute}", :ul_needed => true } -%> <% end %> <% if pagination %>
<%= raw pagination %>
<% end %> <%= raw "
" if ul_needed -%>