Hi,
I have been working to convert the following into a helper method, I
just cant seem to get it right.
Here is what I use now:
=================================================<table
cellspacing="0"  cellpadding="0" border="0"
class="product_tile_all">
<% @products.in_groups_of(3) do |row| %>
<tr>
  <% row.each do |product| %>
  <td align="center" class="product_tile_medium">
        <% @product = product %>
  <div style="background-image:url(<%  
@product.public_filename(:medium) %>);">
  <div>
  <%= image_tag(''overlays/border_medium.gif'') %>
  </div>
  <div class="icon_add_medium">
  <%= link_to image_tag ("icons/add.png"),
  :action => "add_to_cart", :id => product %>
  </div>
  <div class="icon_info_medium">
  <%= link_to image_tag ("icons/information.png"),
  :action => "info", :id => product %>
  </div>
  </div>
  </td>
  <% end -%>
</tr>
<% end -%>
</table>
=================================================
What I am trying to do is create a help that takes 3 things, my
@products, the size I desire (above its medium) and finally the
in_groups_of param.
Any hints on how to get started in constructing this?
Thanks
-- 
Posted via http://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
-~----------~----~----~----~------~----~------~--~---
This is the closest I have gotten, can anyone help?
  def render_product_tiles(products, options = {})
    size = options[:size]
    amount = options[:groups]
    "<table cellspacing=\"0\"  cellpadding=\"0\"
border=\"0\"
class=\"product_tile_all\">"
    products.in_groups_of(amount) do |row|
      "<tr>"
      row.each do |product|
        "<td align=\"center\"
class=\"product_tile_#{size}\">"
          @product = product
          "<div style=\"background-image:url(<%= 
@product.cover.public_filename(:#{size}) %>);\">"
            "<div>"
              image_tag(''overlays/border_#{size}.gif'')
            "</div>"
            "<div class=\"icon_add_#{size}\">"
              link_to image_tag ("icons/add.png"), :action => 
"add_to_cart", :id => product
            "</div>"
            "<div class=\"icon_info_#{size}\">"
              link_to image_tag ("icons/information.png"), :action
=>
"album", :id => product
            "</div>"
          "</div>"
        "</td>"
    end
    "</tr>"
  end
  "</table>"
end
-- 
Posted via http://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
-~----------~----~----~----~------~----~------~--~---
Is there any reason you are doing this as a helper rather than either a.) a partial or b.) a helper with a partial? V/r Anthony Eden On 12/3/06, Shai Shefer <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > This is the closest I have gotten, can anyone help? > > def render_product_tiles(products, options = {}) > size = options[:size] > amount = options[:groups] > "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" > class=\"product_tile_all\">" > products.in_groups_of(amount) do |row| > "<tr>" > row.each do |product| > "<td align=\"center\" class=\"product_tile_#{size}\">" > @product = product > "<div style=\"background-image:url(<%> @product.cover.public_filename(:#{size}) %>);\">" > > "<div>" > image_tag(''overlays/border_#{size}.gif'') > "</div>" > > "<div class=\"icon_add_#{size}\">" > link_to image_tag ("icons/add.png"), :action => > "add_to_cart", :id => product > "</div>" > > "<div class=\"icon_info_#{size}\">" > link_to image_tag ("icons/information.png"), :action => > "album", :id => product > "</div>" > > "</div>" > "</td>" > end > "</tr>" > end > "</table>" > end > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Cell: 808 782-5046 Current Location: Melbourne, FL --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Shai Shefer wrote:>> This is the closest I have gotten, can anyone help? >> >> def render_product_tiles(products, options = {}) >> size = options[:size] >> amount = options[:groups] >> "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" >> class=\"product_tile_all\">" >> products.in_groups_of(amount) do |row| >> "<tr>"I don''t get it. I didn''t know you could generate HTML using unassigned strings like that. Why aren''t you using xml = Builder::XmlMarkup.new ? That would go...>> row.each do |product|xml.td :align => :center, :class => "product_tile_#{size}" do>> @product = productxml.div :style => "etc..." end When you finish, extract the accreted string with xml.target! DRY now becomes a matter of refactoring and squeezing down the xml calls, as raw Ruby. Use my assert_xpath() trick to test that while you squeeze it... If you don''t need this, my post rests in the archives for others to learn from... -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Anthony Eden wrote:> Is there any reason you are doing this as a helper rather than either > a.) a partial or b.) a helper with a partial?Helper is just the first thing that came to mind, if you have a better suggesttion as to how I should approach it, I would definitely be interested. -- Posted via http://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 -~----------~----~----~----~------~----~------~--~---