Created
July 30, 2014 16:17
-
-
Save ijonas/896e35cb6d0be921decb to your computer and use it in GitHub Desktop.
Not using default scope
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 < ActiveRecord::Base | |
validates :title, :description, :image_url, :presence=> true | |
validates :price, :numericality => {:greater_than_or_equal_to => 0.01} | |
validates :title, :uniqueness => true | |
validates :image_url, format: { | |
:with => %r{\.(gif|jpg|png)\Z}i, | |
:message => 'must be a url' | |
} | |
def ordered_by_title | |
order('title') | |
end | |
end | |
class ProductsController < ApplicationController | |
before_action :set_product, only: [:show, :edit, :update, :destroy] | |
# GET /products | |
# GET /products.json | |
def index | |
@products = Product.all.ordered_by_title | |
end | |
# ... | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment