Skip to content

Instantly share code, notes, and snippets.

@hjoseph96
Created February 17, 2015 16:30
Show Gist options
  • Save hjoseph96/73d970f00d83d563c210 to your computer and use it in GitHub Desktop.
Save hjoseph96/73d970f00d83d563c210 to your computer and use it in GitHub Desktop.
no elegance, practicality
def self.practical
where("name LIKE ?", "%Practical%");
end
# in controller
@useful_items = Item.practical
# in view
<% @useful_items.each do |item| %>
<div class="col-sm-3">
<h5><%= item.name %></h5>
<%= link_to(image_tag(item.image_url), item_path(item)) %>
<p>
<%= item.description %>
</p>
</div>
<% end %>
addthree
eligible_orders = where.not(user_id: user_id)
eligible_orders.sample(3).each { |order| order.update(user_id: user_id) }
end
poppin
pop = Item.all.sort_by { |item| item.orders.count }.reverse.first
No ItemOrder tochy
item = Item.first
order = Order.first
item.orders << order
order.items << item
item.orders.include? order
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment