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:
<% @products.in_groups_of(3) do |row| %>
<% row.each do |product| %>
<% @product = product %>
<%= image_tag('overlays/border_medium.gif') %>
<%= link_to image_tag ("icons/add.png"),
:action => "add_to_cart", :id => product %>
<%= link_to image_tag ("icons/information.png"),
:action => "info", :id => product %>
|
<% end -%>
<% end -%>
==================================================
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
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|
“
”
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 class=\"icon_info_#{size}\">"
link_to image_tag ("icons/information.png"), :action =>
“album”, :id => product
“”
"</div>"
"</td>"
end
"</tr>"
end
“”
end
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 E.
On 12/3/06, Shai S. [email protected] wrote:
row.each do |product|
link_to image_tag ("icons/add.png"), :action =>
end
"</tr>"
end
“”
end
–
Posted via http://www.ruby-forum.com/.
–
Cell: 808 782-5046
Current Location: Melbourne, FL
Anthony E. 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.
Shai S. 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|
“”
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 = product
xml.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
Redirecting... ← NOT a blog!!!