Last active
December 29, 2015 13:49
-
-
Save JRizzle88/7680128 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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