Browse Source

Added posts controller; near action to show posts near a point

master
Adrian Short 12 years ago
parent
commit
4c14a86955
8 changed files with 44 additions and 0 deletions
  1. +3
    -0
      app/assets/javascripts/posts.js.coffee
  2. +3
    -0
      app/assets/stylesheets/posts.css.scss
  3. +10
    -0
      app/controllers/posts_controller.rb
  4. +2
    -0
      app/helpers/posts_helper.rb
  5. +11
    -0
      app/views/posts/near.html.haml
  6. +2
    -0
      config/routes.rb
  7. +9
    -0
      test/functional/posts_controller_test.rb
  8. +4
    -0
      test/unit/helpers/posts_helper_test.rb

+ 3
- 0
app/assets/javascripts/posts.js.coffee View File

@@ -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/

+ 3
- 0
app/assets/stylesheets/posts.css.scss View File

@@ -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/

+ 10
- 0
app/controllers/posts_controller.rb View File

@@ -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

+ 2
- 0
app/helpers/posts_helper.rb View File

@@ -0,0 +1,2 @@
module PostsHelper
end

+ 11
- 0
app/views/posts/near.html.haml View File

@@ -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")

+ 2
- 0
config/routes.rb View File

@@ -1,4 +1,6 @@
Apollo::Application.routes.draw do
get "posts/near"

resources :feeds do
member do
get 'fetch'


+ 9
- 0
test/functional/posts_controller_test.rb View File

@@ -0,0 +1,9 @@
require 'test_helper'

class PostsControllerTest < ActionController::TestCase
test "should get near" do
get :near
assert_response :success
end

end

+ 4
- 0
test/unit/helpers/posts_helper_test.rb View File

@@ -0,0 +1,4 @@
require 'test_helper'

class PostsHelperTest < ActionView::TestCase
end

Loading…
Cancel
Save