Shouldn''t your partial use this code:
<%= feature.feature_type.name %>
instead of
<%= @features.feature_type.name %>
@features (if it''s even available in the partial, don''t think
it is
but i''m not sure without testing it) is an array.
@features.feature_type is wrong. When you are testing it in the
console, you are referencing features.first, which is fine.
On Feb 4, 1:36 pm, Pieter Mans
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> I have two object classes:
>
> class Feature < ActiveRecord::Base
> belongs_to :featureable, :polymorphic => true
> belongs_to :feature_type
> end
>
> class FeatureType < ActiveRecord::Base
> has_many :features
> end
>
> I then have a partials which I''m using to iterate out a
collection:
>
> # part of the action from the controller
> def show_template
> @product_template = ProductTemplate.find(params[:id])
> @features = @product_template.features
> end
>
> # from the view
> <%= render :partial => "feature", :collection =>
@features, :locals =>
> removeButton => true } %>
>
> #the partial
> <%= @features.feature_type.name %>, id= <%= feature.id %>
>
> <% if addBut %>
> <%= button_to "Add", :action =>
"add_feature_to_product", :feature
> => feature, :product => @product_template %>
> <% end %>
>
> <% if remBut %>
> <%= button_to "Remove", :action =>
"remove_feature_from_product",
> :id => feature %>
> <% end %>
>
> When I run all this i get the following error:
> undefined method `feature_type'' for Feature:Class
>
> I''ve tried the following in the console and it works fine
there:>> name = features.first.feature_type.name
>
> => "Graphic Design"
>
> Does anyone know why it won''t access the feature''s
feature_type object
> inside the partial?
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---