Skip to content

Instantly share code, notes, and snippets.

@alecguintu
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save alecguintu/c9cb5c29398e08575250 to your computer and use it in GitHub Desktop.

Select an option

Save alecguintu/c9cb5c29398e08575250 to your computer and use it in GitHub Desktop.

Revisions

  1. alecguintu revised this gist Dec 2, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    class Shelf < ActiveRecord::Base
    has_many :comics
    has_many :books
    has_many :books#, validate: -> {self.shelf_of == 'book'}

    accepts_nested_attributes_for :comics
    accepts_nested_attributes_for :books
  2. alecguintu revised this gist Dec 2, 2014. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,18 @@
    class Shelf < ActiveRecord::Base
    has_many :comics
    has_many :books

    accepts_nested_attributes_for :comics
    accepts_nested_attributes_for :books

    # has a dropdown on view for shelf_of that could either be 'comic' or 'book
    validates :shelf_of, inclusion: { within: %w(comic book) }
    end

    class Comic < ActiveRecord::Base

    end

    class Book < ActiveRecord::Base
    validates :title, presence: true
    validates :title, format: { with: /\Asome_complicated_format\z/i }
    end
  3. alecguintu created this gist Dec 2, 2014.
    12 changes: 12 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    class Shelf < ActiveRecord::Base
    has_many :comics
    accepts_nested_attributes_for :comics
    end

    class Comic < ActiveRecord::Base

    end

    class Book < ActiveRecord::Base
    validates :title, presence: true
    end