Browse files

Force locations for posts

  • Loading branch information...
1 parent 236aae2 commit fcb50e699d1a85b27f7c75a6c10766535a15f6c9 @rjshade committed Apr 11, 2012
View
2 app/assets/stylesheets/posts.css.scss
@@ -114,7 +114,7 @@
}
#gmaps-canvas {
width:100%;
- height:400px;
+ height:300px;
@include shadows;
}
#gmaps-error {
View
10 app/controllers/posts_controller.rb
@@ -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
@@ -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])
@@ -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
View
6 app/models/post.rb
@@ -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
View
5 app/views/posts/_form.html.haml
@@ -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
@@ -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'
View
8 app/views/stories/_map.html.haml
@@ -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 }) }}

0 comments on commit fcb50e6

Please sign in to comment.