In my taxons_controller I have the following:

@taxon = Taxon.find_by_permalink(params[:id])
@related_products = @taxon.products.offset(rand(Spree::Product.count)).limit
(7).name

I've tested a form of this and it is pulling a random object, but when I
put it in my show view:

<ul>
<%= @related_products.each do |related_product| %>
<li><%= related_product.name %></li>
<% end %>
</ul>

I get a NoMethodError in Spree/taxons#show

undefined method `each' for "Spree::Product":String

Extracted source (around line *#41*):

38: <% end %>
39: </div><!-- popup-images -->
40: <ul>
41: <%= @related_products.each do |related_product| %>
42: <li><%= related_product.name %></li>
43: <% end %>
44: </ul>

--
You received this message because you are subscribed to the Google Groups "Spree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spree-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Jameson Trinker at Mar 21, 2013 at 8:33 pm
    I figured it out, I'm a dummy. i was iterating a string. Just needed to
    remove the '.name' from the query
    On Thursday, March 21, 2013 3:19:59 PM UTC-5, Jameson Trinker wrote:

    In my taxons_controller I have the following:

    @taxon = Taxon.find_by_permalink(params[:id])
    @related_products = @taxon.products.offset(rand(Spree::Product.count)).
    limit(7).name

    I've tested a form of this and it is pulling a random object, but when I
    put it in my show view:

    <ul>
    <%= @related_products.each do |related_product| %>
    <li><%= related_product.name %></li>
    <% end %>
    </ul>

    I get a NoMethodError in Spree/taxons#show

    undefined method `each' for "Spree::Product":String

    Extracted source (around line *#41*):

    38: <% end %>
    39: </div><!-- popup-images -->
    40: <ul>
    41: <%= @related_products.each do |related_product| %>
    42: <li><%= related_product.name %></li>
    43: <% end %>
    44: </ul>
    --
    You received this message because you are subscribed to the Google Groups "Spree" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to spree-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Laurens Nienhaus at Mar 21, 2013 at 8:35 pm
    check the contents of @related_products variable.

    try with out .name at the end:

    @related_products = @taxon.products.offset(rand(Spree::Product.count)).limit(7)

    On 21 March 2013 21:19, Jameson Trinker wrote:
    In my taxons_controller I have the following:

    @taxon = Taxon.find_by_permalink(params[:id])
    @related_products =
    @taxon.products.offset(rand(Spree::Product.count)).limit(7).name

    I've tested a form of this and it is pulling a random object, but when I put
    it in my show view:

    <ul>
    <%= @related_products.each do |related_product| %>
    <li><%= related_product.name %></li>
    <% end %>
    </ul>

    I get a NoMethodError in Spree/taxons#show

    undefined method `each' for "Spree::Product":String

    Extracted source (around line #41):

    38: <% end %>
    39: </div><!-- popup-images -->
    40: <ul>
    41: <%= @related_products.each do |related_product| %>
    42: <li><%= related_product.name %></li>
    43: <% end %>
    44: </ul>

    --
    You received this message because you are subscribed to the Google Groups
    "Spree" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to spree-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "Spree" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to spree-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupspree-user @
categoriesrubyonrails
postedMar 21, '13 at 8:20p
activeMar 21, '13 at 8:35p
posts3
users2
websitespreecommerce.com
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase