Skip to content

Commit

Permalink
Change background image and location user post association
Browse files Browse the repository at this point in the history
  • Loading branch information
floalex committed Sep 20, 2015
1 parent 93ed6dd commit 87b3ea0
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 21 deletions.
23 changes: 19 additions & 4 deletions app/assets/stylesheets/static_pages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,35 @@ footer#page-footer {
}
}

.slide1, .slide2, .slide3 {
.slide1, .slide2, .slide3, slide4, slide5, slide6, slide7, slide8 {
min-height: 600px; /* Must have a height or min-height set due to use of background images */
background-size: cover;
-moz-background-size: cover;
background-position: center center;
}
.slide1 {
background-image: url('https://s3-us-west-2.amazonaws.com/petshome-ca/background/dogs_on_cart.png');
background-image: url('https://s3-us-west-2.amazonaws.com/petshome-ca/background/dogs_in_cart.png');
}
.slide2 {
background-image: url('https://s3-us-west-2.amazonaws.com/petshome-ca/background/lovers_and_dogs.png');
background-image: url('https://s3-us-west-2.amazonaws.com/petshome-ca/background/jimwin2dogs.png');
}
.slide3 {
background-image: url('https://s3-us-west-2.amazonaws.com/petshome-ca/background/white_cat.png');
background-image: url('https://s3-us-west-2.amazonaws.com/petshome-ca/background/yogulookup.png');
}
.slide4 {
background-image: url('https://s3-us-west-2.amazonaws.com/petshome-ca/background/paigouside.png');
}
.slide5 {
background-image: url('https://s3-us-west-2.amazonaws.com/petshome-ca/background/tiggerside.png');
}
.slide6 {
background-image: url('https://s3-us-west-2.amazonaws.com/petshome-ca/background/winflo2dogs.png');
}
.slide7{
background-image: url('https://s3-us-west-2.amazonaws.com/petshome-ca/background/yoguside.png');
}
.slide8 {
background-image: url('https://s3-us-west-2.amazonaws.com/petshome-ca/background/tiggercloseup.png');
}

/* Carousel Overlay */
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/categories/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def new
if current_user.locations.first
@post.location = current_user.locations.first
else
@post.build_location
@post.locations.build
end

end
Expand All @@ -32,12 +32,12 @@ def create

def edit
@post = Post.find(params[:id])
if @post.location.blank?
if @post.locations.blank?

if current_user.locations.first
@post.location = current_user.locations.first
else
@post.build_location
@post.locations.build
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/location.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Location < ActiveRecord::Base
belongs_to :post
has_one :user, through: :post
belongs_to :user

validates :street, format: { with: /\A[a-z0-9\s]+\z/i, allow_blank: true }
validates :city, presence: true
Expand Down
10 changes: 4 additions & 6 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ class Post < ActiveRecord::Base
belongs_to :user
belongs_to :category

has_one :location, dependent: :destroy

accepts_nested_attributes_for :location,

allow_destroy: true

has_many :locations, through: :user

accepts_nested_attributes_for :locations,
reject_if: proc { |attributes| attributes['name'].blank? },
allow_destroy: true


default_scope { order('created_at DESC') }
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class User < ActiveRecord::Base
before_save :downcase_email
before_create :create_activation_digest
has_many :posts, dependent: :destroy
has_many :locations, through: :posts
has_many :locations, dependent: :destroy
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 250 },
Expand Down
4 changes: 2 additions & 2 deletions app/views/categories/posts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

</div>
<div class="col-md-4">
<% if @post.location.present? %>
<% if @post.locations.present? %>
<iframe width="230" height="230" frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?&key=<%= ENV['googlemap_api_key'] %>&q=<%= @post.location.zipcode %>&zoom=14"></iframe>


<% unless @post.location.street.blank? %>
<% unless @post.locations.street.blank? %>
<p><%= "#{@post.location.street}, #{@post.location.city}, #{@post.location.zipcode}".html_safe %></p>
<% end %>
<% end %>
Expand Down
15 changes: 15 additions & 0 deletions app/views/static_pages/home.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@
<div class="item">
<div class="slide3"></div>
</div>
<div class="item">
<div class="slide4"></div>
</div>
<div class="item">
<div class="slide5"></div>
</div>
<div class="item">
<div class="slide6"></div>
</div>
<div class="item">
<div class="slide7"></div>
</div>
<div class="item">
<div class="slide8"></div>
</div>
</div><!-- .carousel-inner -->
<div class="container carousel-overlay text-center">
<h1>Welcome to the Pet Home!</h1>
Expand Down
1 change: 0 additions & 1 deletion db/migrate/20150801064532_create_locations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ def change
t.string :street
t.string :city
t.integer :zipcode
t.references :post, index: true, foreign_key: true

t.timestamps null: false
end
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20150920031252_add_user_to_locations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddUserToLocations < ActiveRecord::Migration
def change
add_column :locations, :user_id, :integer
add_index :locations, :user_id
end
end
6 changes: 3 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150801064532) do
ActiveRecord::Schema.define(version: 20150920031252) do

create_table "categories", force: :cascade do |t|
t.string "name"
Expand Down Expand Up @@ -40,12 +40,12 @@
t.string "street"
t.string "city"
t.integer "zipcode"
t.integer "post_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
end

add_index "locations", ["post_id"], name: "index_locations_on_post_id"
add_index "locations", ["user_id"], name: "index_locations_on_user_id"

create_table "posts", force: :cascade do |t|
t.string "title"
Expand Down
Empty file added test/controllers/.keep
Empty file.
Empty file added test/fixtures/.keep
Empty file.
Empty file added test/helpers/.keep
Empty file.
Empty file added test/integration/.keep
Empty file.
Empty file added test/mailers/.keep
Empty file.
Empty file added test/models/.keep
Empty file.
10 changes: 10 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all

# Add more helper methods to be used by all tests here...
end

0 comments on commit 87b3ea0

Please sign in to comment.