Skip to content

Commit

Permalink
added production filter in map partial to guess location on ip addres…
Browse files Browse the repository at this point in the history
…s, added new model Rating, will soon be fixed
  • Loading branch information
Kevin Quinn committed Jul 17, 2011
1 parent 44d6e1c commit fa33d91
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 11 deletions.
4 changes: 3 additions & 1 deletion app/controllers/application_controller.rb
@@ -1,5 +1,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery

helper :all
before_filter :geokit

geocode_ip_address
Expand All @@ -13,5 +15,5 @@ def store_location
session[:return_to] = request.request_uri
end

protect_from_forgery

end
6 changes: 6 additions & 0 deletions app/controllers/stories_controller.rb
@@ -1,6 +1,7 @@
class StoriesController < ApplicationController

before_filter :set_place
before_filter :set_rating

# GET /places/1/stories
# GET /places/1//stories.xml
Expand All @@ -17,6 +18,7 @@ def index
# GET /places/1//stories/1.xml
def show
@story = @place.stories.find(params[:id])
@rating = @place.ratings.find(params[:id])

respond_to do |format|
format.html # show.html.erb
Expand Down Expand Up @@ -89,5 +91,9 @@ def destroy
def set_place
@place = Place.find(params[:place_id])
end

def set_rating
@rating = Rating.find(params[:rating_id])
end

end
13 changes: 13 additions & 0 deletions app/models/rating.rb
@@ -0,0 +1,13 @@
class Rating < ActiveRecord::Base

belongs_to :story
belongs_to :user

def already_awesomed?
@rating.each do |rating|
rating.user_id == @current_user.id && rating.story_id == @story.find(params[:id])
end
end


end
1 change: 0 additions & 1 deletion app/models/story.rb
Expand Up @@ -3,5 +3,4 @@ class Story < ActiveRecord::Base
belongs_to :user
belongs_to :place


end
20 changes: 12 additions & 8 deletions app/views/layouts/_map.html.erb
Expand Up @@ -2,14 +2,18 @@

<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
<% if Rails.env.production? %>
var latlng = new google.maps.LatLng(<%= @current_location.lat %>, <%= @current_location.lng %>);
<% else %>
var latlng = new google.maps.LatLng( 33.748, -84.388 );
<% end %>
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);

//delete this comment later, pasting from swarm, update variables, etc, accordingly

Expand Down
7 changes: 7 additions & 0 deletions app/views/stories/show.html.erb
Expand Up @@ -3,6 +3,13 @@
<p>
<b>Title:</b>
<%= @story.title %>
<b>Awesome Value:</b>
<%= @story.value %>
<% if @rating.already_awesomed? %>
<p> You like this story! </p>
<% else %>
<% button_to "Awesome This" %>
<% end %>
</p>

<p>
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20110716191442_add_rating_to_stories.rb
@@ -0,0 +1,9 @@
class AddRatingToStories < ActiveRecord::Migration
def self.up
add_column :stories, :rating, :integer
end

def self.down
remove_column :stories, :rating
end
end
14 changes: 14 additions & 0 deletions db/migrate/20110716204910_create_ratings.rb
@@ -0,0 +1,14 @@
class CreateRatings < ActiveRecord::Migration
def self.up
create_table :ratings do |t|
t.integer :user_id
t.integer :story_id

t.timestamps
end
end

def self.down
drop_table :ratings
end
end
@@ -0,0 +1,8 @@
class ChangeColumnInStoriesFromRatingsToValue < ActiveRecord::Migration
def self.up
rename_column :stories, :rating, :value
end

def self.down
end
end
10 changes: 9 additions & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110713013644) do
ActiveRecord::Schema.define(:version => 20110716223614) do

create_table "places", :force => true do |t|
t.float "lat"
Expand All @@ -22,13 +22,21 @@
t.integer "story_id"
end

create_table "ratings", :force => true do |t|
t.integer "user_id"
t.integer "story_id"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "stories", :force => true do |t|
t.string "title"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "place_id"
t.text "content"
t.integer "value"
end

create_table "users", :force => true do |t|
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/ratings.yml
@@ -0,0 +1,9 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
user_id: 1
story_id: 1

two:
user_id: 1
story_id: 1
8 changes: 8 additions & 0 deletions test/unit/rating_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'

class RatingTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

0 comments on commit fa33d91

Please sign in to comment.