Skip to content

Commit 4ae3db9

Browse files
committed
changes
1 parent b4ea3f5 commit 4ae3db9

File tree

15 files changed

+79
-17
lines changed

15 files changed

+79
-17
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ gem 'turbolinks'
2727
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
2828
gem 'jbuilder', '~> 1.2'
2929

30+
gem 'httparty'
31+
3032
group :doc do
3133
# bundle exec rake doc:rails generates the API under doc/api.
3234
gem 'sdoc', require: false

Gemfile.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ GEM
5353
guard (~> 2.1)
5454
rspec (>= 2.14, < 4.0)
5555
hike (1.2.3)
56+
httparty (0.12.0)
57+
json (~> 1.8)
58+
multi_xml (>= 0.5.2)
5659
i18n (0.6.9)
5760
jbuilder (1.5.3)
5861
activesupport (>= 3.0.0)
@@ -73,6 +76,7 @@ GEM
7376
mime-types (1.25.1)
7477
minitest (4.7.5)
7578
multi_json (1.8.3)
79+
multi_xml (0.5.5)
7680
pg (0.17.1)
7781
polyglot (0.3.3)
7882
pry (0.9.12.4)
@@ -162,6 +166,7 @@ PLATFORMS
162166
DEPENDENCIES
163167
coffee-rails (~> 4.0.0)
164168
guard-rspec
169+
httparty
165170
jbuilder (~> 1.2)
166171
jquery-rails
167172
pg

app/assets/javascripts/application.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ $(document).ready(function(){
2020
$('#hover').click(function(){
2121
$('#create-message').fadeIn(5000);
2222
});
23-
});
23+
$('.display_form').click(function(){
24+
//$(".switch").toggle()
25+
});
26+
});
27+

app/assets/stylesheets/contact.css.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ div.field {
2525
margin-bottom: 20px;
2626
}
2727

28-
div#message input {
28+
textarea#contact_message {
2929
width: 400px;
3030
height: 200px;
31+
}
32+
33+
span#label {
34+
vertical-align: top;
3135
}

app/assets/stylesheets/welcome.css.scss

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@ div#create-message {
4646
margin-left: 80px;
4747
margin-top: -450px;
4848
width: 250px;
49-
display: none;
50-
}
49+
display: none;}
5150

5251
a {color: purple;
5352
font-family: 'Lobster', cursive;
54-
text-transform: uppercase;
55-
}
53+
text-transform: uppercase;}
5654

5755
div#part2 {
5856
background: black;
5957
height: 900px;
60-
width: auto;
61-
display: none;}
58+
width: auto;}

app/controllers/application_controller.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,33 @@ def current_visitor
88
@current_visitor ||= if session[:visitor_id]
99
Visitor.find(session[:visitor_id])
1010
else
11-
visitor = Visitor.create(ip_address: request.remote_ip, mobile: mobile_device?)
11+
visitor = Visitor.create(ip_address: request.remote_ip, mobile: mobile_device?, country: get_ip(request.remote_ip), browser: browser_name)
1212
session[:visitor_id] = visitor.id
1313
visitor
1414
end
1515
end
1616
helper_method :current_visitor
1717

18+
def get_ip(ip)
19+
HTTParty.get("http://freegeoip.net/json/#{ip}").parsed_response["country_name"]
20+
end
21+
1822

1923
def mobile_device?
2024
request.user_agent.downcase.include?("mobile")
2125
end
2226
helper_method :mobile_device?
27+
28+
29+
def browser_name
30+
if request.user_agent.downcase.include?("firefox")
31+
"firefox"
32+
elsif request.user_agent.downcase.include?("gecko")
33+
"safari"
34+
elsif request.user_agent.downcase.include?("msie")
35+
"internet explorer"
36+
else
37+
"unknown"
38+
end
39+
end
2340
end

app/controllers/welcome_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class WelcomeController < ApplicationController
22
before_action :update_visit_count
33

44
def index
5+
@contact = Contact.new
56
end
67

78
def update_visit_count

app/models/visitor.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ def self.non_mobile_users
2121
def self.total_visitors
2222
sum(:page_visits)
2323
end
24+
25+
def self.firefox_users
26+
where(browser: firefox)
27+
end
2428

2529
end

app/views/admin/index.html.erb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,16 @@
3636
<td><%= Visitor.non_mobile_users.count %></td>
3737
</tr>
3838
</table>
39+
40+
<table class="browser">
41+
<tr>
42+
<th>Mobile Visitors:</th>
43+
<th>Non-Mobile Visitors:</th>
44+
</tr>
45+
46+
<tr>
47+
<td><%= Visitor.mobile_users.count %></td>
48+
<td><%= Visitor.non_mobile_users.count %></td>
49+
</tr>
50+
</table>
3951
</div>

app/views/contact/new.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<%= f.text_field :email %>
1313
</div>
1414
<div class="field" id="message">
15-
<%= f.label :message %>
16-
<%= f.text_field :message %>
15+
<span id="label"> <%= f.label :message %></span>
16+
<%= f.text_area :message %>
1717
</div>
1818
<div class="actions">
1919
<%= f.submit "Submit" %>

0 commit comments

Comments
 (0)