Appreciate any help on following with rails 2.3.4 and AS.

Here is model --

class DetailFungicide < ActiveRecord::Base
  has_one :product, :as => :detail
  has_many :df_whens, :order => :position, :dependent => :destroy
  has_many :df_hows, :order => :position, :dependent => :destroy
  has_many :df_whats, :order => :position, :dependent => :destroy
  has_many :df_benefits, :order => :position, :dependent => :destroy
  has_many :fungicide_ingredients, :as
=> :detail_fungicide, :dependent => :destroy
  has_many :affected_fungus, :as => :detail_fungicide, :dependent
=> :destroy

  def product_name
    self.product.name
  end

  def contains
    if self.fungicide_ingredients.empty?
      "Contains"
    else
      fungicide_ingredients.collect { |fi|
        [(fi.base_chemical.common_name.nil? ?
fi.base_chemical.chemical_name :
fi.base_chemical.common_name ) ]}.uniq.join "; "
    end
  end

  def fungi
    if self.affected_fungus.empty?
      "Fungus"
    else
      affected_fungus.collect { |af| [af.base_fungus.name]}.join "; "
    end
  end

  def when_count
    self.df_whens.count
  end

  def how_count
    self.df_hows.count
  end

  def what_count
    self.df_whats.count
  end

  def benefit_count
    self.df_benefits.count
  end

  def to_label
    "#{self.product.name}"
  end
end


Here is controller --

class Admin::DetailFungicideController < Admin::AdminController
  active_scaffold :detail_fungicide do |config|
    config.label = "Product Details"

    # virtual columns for visibility to count stats.
    config.columns =
[:product_name, :formulation, :contains, :fungi, :when_count, :how_count, 
:what_count,  :benefit_count]
    config.columns[:when_count].label = "When #"
    config.columns[:how_count].label = "How #"
    config.columns[:what_count].label = "What #"
    config.columns[:benefit_count].label = "Benefit #"

    config.list.columns =
[ :product_name, :formulation, :contains, :fungi, :when_count, :how_count, 
:what_count,  :benefit_count]
    config.columns[:contains].label = "Contains"

    # allow separate edit on each count attribute ...
    columns[:when_count].set_link 'nested', :parameters =>
{:associations => :df_whens}
    columns[:how_count].set_link 'nested', :parameters =>
{:associations => :df_hows}
    columns[:what_count].set_link 'nested', :parameters =>
{:associations => :df_whats}
    columns[:benefit_count].set_link 'nested', :parameters =>
{:associations => :df_benefits}

    # ... also allow all count attribute edit at once
    config.nested.add_link("Product Details",
[:df_whens, :df_hows, :df_whats, :df_benefits])

    # no simple attributes to work with
    config.actions.exclude :show
    config.actions.exclude :create
    config.actions.exclude :delete

    # don't want the explicit Edit button
    config.update.link.label = ""

    config.update.columns.exclude
[:product_name, :contains, :fungi, :when_count, :how_count, :what_count,  
:benefit_count]
  end

  # This is used by :list action.
  # Without this condition then all records for this model are
returned -- and we don't want that since there is only one detail/
product.
  def conditions_for_collection
    ['detail_fungicides.id = (?)', params[:id]]
  end
end

Here are helpers that don't seem to be called --


module Admin::DetailFungicideHelper
   def formulation_column(record)
    link_to((record.formulation.empty? ? "Formulation" :
record.formulation),
      {:controller => "admin/detail_fungicide",
        :action => :edit,
        :_method => :get,
        :id => "#{record.id}",
        :parent_controller => "admin/product" },
      {:id => "#{action_link_id('edit', record.id) }",
        :class => "nested action",
        :position => "after"})
      end

   def contains_column(record)
    link_to(record.contains,
      {:controller => "admin/detail_fungicide",
        :action => :nested,
        :_method => :get,
        :associations => :fungicide_ingredients,
        :id => "#{record.id}",
        :parent_controller => "admin/product" },
      {:id => "#{action_link_id('edit', record.id) }",
        :class => "nested action",
        :position => "after"})
  end

  def fungi_column(record)
    link_to(record.fungi,
      {:controller => "admin/detail_fungicide",
        :action => :nested,
        :_method => :get,
        :associations => :affected_fungus,
        :id => "#{record.id}",
        :parent_controller => "admin/product" },
      {:id => "#{action_link_id('edit', record.id) }",
        :class => "nested action",
        :position => "after"})
  end
end




AND Finally view generated output has incorrect controller referenced
(/admin/detail_weeding_lawn/edit/1)  for "formulation" and "contains"
but correct for "fungi" --

<tr class="record " id="as_admin__detail_fungicide-list-1-row">


    <td class="product_name-column " >
      ORTHO RosePride Rose & Shrub Disease Control
    </td>


    <td class="formulation-column " >
      <a href="/admin/detail_weeding_lawn/edit/1?
_method=get&parent_controller=admin%2Fproduct" class="nested
action" id="as_admin__detail_fungicide-edit-1-link"
position="after">Formulation</a>
    </td>


    <td class="contains-column " >
      <a href="/admin/detail_weeding_select/nested/1?
_method=get&associations=weeding_ingredients&parent_controller=admin
%2Fproduct" class="nested action" id="as_admin__detail_fungicide-
edit-1-link" position="after">Triforine</a>
    </td>


    <td class="fungi-column " >
      <a href="/admin/detail_fungicide/nested/1?
_method=get&associations=affected_fungus&parent_controller=admin
%2Fproduct" class="nested action" id="as_admin__detail_fungicide-
edit-1-link" position="after">Black spot; Powdery mildew; Rust</a>
    </td>


-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en.

Reply via email to