Skip to content

Instantly share code, notes, and snippets.

@JRizzle88
Last active December 29, 2015 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JRizzle88/7680128 to your computer and use it in GitHub Desktop.
Save JRizzle88/7680128 to your computer and use it in GitHub Desktop.
#/views/products/index.html.erb
<div class="hide-for-small panel">
<h3>Sidebar</h3>
<h5 class="subheader">Feature Product</h5>
<% Product.random do |product|%>
<%= image_tag(Product.image_url) %>
<h5><%= link_to Product.title, product %></h5>
<p><%= button_to 'Add to Cart', line_items_path(:product_id => product) %></p>
<% end %>
</div>
#/models/products.rb
class Product < ActiveRecord::Base
def Product.random
find.limit(1).offset(rand(self.count)).first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment