From 4c14a86955d58ded8110384610ed9d07e3347dc7 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Tue, 26 Jun 2012 15:06:19 +0100 Subject: [PATCH] Added posts controller; near action to show posts near a point --- app/assets/javascripts/posts.js.coffee | 3 +++ app/assets/stylesheets/posts.css.scss | 3 +++ app/controllers/posts_controller.rb | 10 ++++++++++ app/helpers/posts_helper.rb | 2 ++ app/views/posts/near.html.haml | 11 +++++++++++ config/routes.rb | 2 ++ test/functional/posts_controller_test.rb | 9 +++++++++ test/unit/helpers/posts_helper_test.rb | 4 ++++ 8 files changed, 44 insertions(+) create mode 100644 app/assets/javascripts/posts.js.coffee create mode 100644 app/assets/stylesheets/posts.css.scss create mode 100644 app/controllers/posts_controller.rb create mode 100644 app/helpers/posts_helper.rb create mode 100644 app/views/posts/near.html.haml create mode 100644 test/functional/posts_controller_test.rb create mode 100644 test/unit/helpers/posts_helper_test.rb diff --git a/app/assets/javascripts/posts.js.coffee b/app/assets/javascripts/posts.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/posts.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/posts.css.scss b/app/assets/stylesheets/posts.css.scss new file mode 100644 index 0000000..1a7e153 --- /dev/null +++ b/app/assets/stylesheets/posts.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the posts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb new file mode 100644 index 0000000..07af7be --- /dev/null +++ b/app/controllers/posts_controller.rb @@ -0,0 +1,10 @@ +class PostsController < ApplicationController + def near + @posts = Post.near(params[:lat].to_f, params[:lng].to_f, params[:radius].to_f) + + respond_to do |format| + format.html # near.html.erb + format.json { render json: @posts } + end + end +end diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb new file mode 100644 index 0000000..a7b8cec --- /dev/null +++ b/app/helpers/posts_helper.rb @@ -0,0 +1,2 @@ +module PostsHelper +end diff --git a/app/views/posts/near.html.haml b/app/views/posts/near.html.haml new file mode 100644 index 0000000..3a14668 --- /dev/null +++ b/app/views/posts/near.html.haml @@ -0,0 +1,11 @@ +%h1 Posts#near + +%table + - @posts.each do |p| + %tr + %td= link_to p.title, p.url + %td= p.loc['lat'] + %td= p.loc['lng'] + %td + - unless p.published.nil? + = p.published.strftime("%d %b %Y %H:%M") diff --git a/config/routes.rb b/config/routes.rb index 5054179..21b5390 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Apollo::Application.routes.draw do + get "posts/near" + resources :feeds do member do get 'fetch' diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb new file mode 100644 index 0000000..f3f3e80 --- /dev/null +++ b/test/functional/posts_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class PostsControllerTest < ActionController::TestCase + test "should get near" do + get :near + assert_response :success + end + +end diff --git a/test/unit/helpers/posts_helper_test.rb b/test/unit/helpers/posts_helper_test.rb new file mode 100644 index 0000000..48549c2 --- /dev/null +++ b/test/unit/helpers/posts_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class PostsHelperTest < ActionView::TestCase +end