diff --git a/app/models/lodging.rb b/app/models/lodging.rb new file mode 100644 index 00000000..b7eddb9f --- /dev/null +++ b/app/models/lodging.rb @@ -0,0 +1,10 @@ +class Lodging < ActiveRecord::Base + attr_accessible :name, :description, :photo + belongs_to :venue + has_attached_file :photo, + styles: { thumb: '100x100>', large: '300x300>' } + + validates_attachment_content_type :photo, + content_type: [/jpg/, /jpeg/, /png/, /gif/], + size: { in: 0..500.kilobytes } +end diff --git a/app/models/venue.rb b/app/models/venue.rb index c63cb69b..c7cb2640 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -1,6 +1,7 @@ class Venue < ActiveRecord::Base - attr_accessible :name, :description, :website, :address, :photo + attr_accessible :name, :description, :website, :address,:photo, :lodgings_attributes has_many :conferences + has_many :lodgings before_create :generate_guid has_attached_file :photo, styles: { thumb: '100x100>', large: '300x300>' } @@ -8,6 +9,7 @@ class Venue < ActiveRecord::Base validates_attachment_content_type :photo, content_type: [/jpg/, /jpeg/, /png/, /gif/], size: { in: 0..500.kilobytes } + accepts_nested_attributes_for :lodgings, allow_destroy: true private def generate_guid diff --git a/db/migrate/20140604061951_create_lodgings.rb b/db/migrate/20140604061951_create_lodgings.rb new file mode 100644 index 00000000..45412bcc --- /dev/null +++ b/db/migrate/20140604061951_create_lodgings.rb @@ -0,0 +1,14 @@ +class CreateLodgings < ActiveRecord::Migration + def change + create_table :lodgings do |t| + t.string :name + t.text :description + t.string :photo_file_name + t.string :photo_content_type + t.integer :photo_file_size + t.datetime :photo_updated_at + t.belongs_to :venue + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6d9c6744..a3d9c00c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -192,6 +192,18 @@ ActiveRecord::Schema.define(version: 20140613083115) do t.integer "event_id" end + create_table "lodgings", force: true do |t| + t.string "name" + t.text "description" + t.string "photo_file_name" + t.string "photo_content_type" + t.integer "photo_file_size" + t.datetime "photo_updated_at" + t.integer "venue_id" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "people", force: true do |t| t.string "guid", null: false t.string "first_name", default: "" diff --git a/spec/factories/lodgings.rb b/spec/factories/lodgings.rb new file mode 100644 index 00000000..d5481b83 --- /dev/null +++ b/spec/factories/lodgings.rb @@ -0,0 +1,9 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :lodging do + name 'Example Hotel' + description 'Lorem Ipsum Dolor' + venue + end +end