Class: PingController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ping_controller.rb

Constant Summary

Constants included from PaginationHelper

PaginationHelper::DEFAULT_OPTIONS, PaginationHelper::OPTIONS

Instance Method Summary collapse

Methods included from PaginationHelper

included, #paginate, validate_options!

Instance Method Details

#trackbackObject

This implements trackback functionality for other people tracking back to our elite journal. This method should have a post id passed in the url and the following are posted:

title
excerpt
url
blog_name

Url is the only field we’ll require, and we’ll use that for title if title isn’t passed in.

Errors that we’ll spew back in the faces of those unelite enough to send us garbage:

1 - They didn't send an ID or a URL, both are required.
2 - They tried to trackback to a BS post number.
3 - For whatever damn reason, the trackback didn't save in the db.  Gnomes.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/ping_controller.rb', line 18

def trackback
  @error   = '0'
  @message = nil

  unless @params['id'] and @params['url']
    @error   = '1'
    @message = 'Parameters missing.'
    return
  end

  begin
    post           = Post.find(@params['id'])
    ping           = post.build_to_pings
    ping.title     = @params['title'] || @params['url']
    ping.excerpt   = @params['excerpt'] || ''
    ping.url       = @params['url']
    ping.blog_name = @params['blog_name'] || ''
    unless ping.save
      @error   = '3'
      @message = 'TrackBack Ping not saved.'
    end
  rescue ActiveRecord::RecordNotFound, ActiveRecord::StatementInvalid
    @error = '2'
    @message = 'Post not found.'
  end
end