Created
November 7, 2016 15:50
-
-
Save jtperreault/4d7ae00d7c48128ab49298e76fc69bf9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<div class="row"> | |
<% @categories.each do |category|%> | |
<h2><%=category.name%></h2> | |
<%= image_tag category.image.thumb.url%> | |
<ul> | |
<%= category.products.published.each do |product| %> | |
<li><%=product.name%></li> | |
<li><%=product.price%></li> | |
<li><%=product.description%></li> | |
<% end %> | |
</br> | |
</ul> | |
<% end %> | |
</div> |
This file contains hidden or 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
class Product < ApplicationRecord | |
scope :published, -> { | |
where(:is_published => true) | |
} | |
belongs_to :category | |
validates_presence_of :name, :price | |
mount_uploader :image, ImageUploader | |
validates_processing_of :image | |
validate :image_size_validation | |
private | |
def image_size_validation | |
errors[:image] << "Η εικόνα πρέπει να είναι μικρότερη απο 3MB." if image.size > 3.megabytes | |
end | |
end |
This file contains hidden or 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
class ProductsController < ApplicationController | |
def index | |
@categories = Category.published.order("position") | |
@products = Product.where(is_published: true).order("position") | |
end | |
def show | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment