Skip to content

Commit

Permalink
Force locations for posts
Browse files Browse the repository at this point in the history
  • Loading branch information
rjshade committed Apr 11, 2012
1 parent 236aae2 commit fcb50e6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/posts.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
}
#gmaps-canvas {
width:100%;
height:400px;
height:300px;
@include shadows;
}
#gmaps-error {
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def show
end

def new
@story = current_user.stories.find_by_slug(params[:story_id])
@story = Story.find_by_slug(params[:story_id])
@post = @story.posts.build
end

def create
@story = current_user.stories.find_by_slug(params[:story_id])
@story = Story.find_by_slug(params[:story_id])
@post = @story.posts.build(params[:post])

if @post.save
Expand All @@ -28,12 +28,12 @@ def create
end

def edit
@story = current_user.stories.find_by_slug(params[:story_id])
@story = Story.find_by_slug(params[:story_id])
@post = @story.posts.find_by_slug(params[:id])
end

def update
@story = current_user.stories.find_by_slug(params[:story_id])
@story = Story.find_by_slug(params[:story_id])
@post = @story.posts.find_by_slug(params[:id])

if @post.update_attributes(params[:post])
Expand All @@ -44,7 +44,7 @@ def update
end

def destroy
@story = current_user.stories.find_by_slug(params[:story_id])
@story = Story.find_by_slug(params[:story_id])
@post = @story.posts.find_by_slug(params[:id])

if @post.destroy
Expand Down
6 changes: 6 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class Post
slug :title, :scope => :story
validates :title, presence: true, allow_blank: false, allow_nil: false

validates_presence_of :address, message: "where did this happen?"
validates_presence_of :date, message: "when did this happen?"
validates_presence_of :text
validates_presence_of :latitude, message: "click on the map"
validates_presence_of :longitude, message: "click on the map"

field :text, :type => String

field :address, :type => String
Expand Down
5 changes: 3 additions & 2 deletions app/views/posts/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
= f.input :address, input_html: {id: 'gmaps-input-address'},
placeholder: 'Start typing a place name...',
label: "Location"
%p Latitude and longitude are determined when a valid place name is entered, or the map is clicked
= f.input :latitude, :disabled => true, :input_html => {:id => 'gmaps-output-latitude'}
= f.input :longitude, :disabled => true, :input_html => {:id => 'gmaps-output-longitude'}
#gmaps-error.alert.alert-error
#gmaps-canvas

Expand All @@ -37,8 +40,6 @@
- if @post.image?
.center
= image_tag @post.image.url(:large), class: 'photo'
= f.input :latitude, :as => :hidden, :input_html => {:id => 'gmaps-output-latitude'}
= f.input :longitude, :as => :hidden, :input_html => {:id => 'gmaps-output-longitude'}
.form-actions
.span12
= f.button :submit, "Submit post", :class => 'btn btn-large'
Expand Down
8 changes: 4 additions & 4 deletions app/views/stories/_map.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- output = @story.posts_with_locations.map{|p| { 'address' => p.address,
'latitude' => p.latitude,
'longitude' => p.longitude,
'post_id' => p.id,
- output = @story.posts.latest.map{|p| { 'address' => p.address,
'latitude' => p.latitude,
'longitude' => p.longitude,
'post_id' => p.id,
'post_link' => (link_to (truncate(p.title) + " »".html_safe).html_safe, story_post_path(p.story,p)),
'content' => (render partial: 'posts/info_window', locals: { post: p }) }}

Expand Down

0 comments on commit fcb50e6

Please sign in to comment.