2010-08-30 50 views
1

所以我幾乎有一個pingback發送器準備好我的rails應用程序(人們發佈鏈接到內容並捐贈給他們)。幾乎。Rails:爲什麼我在pingback上得到錯誤的鏈接?

我從這裏的代碼沉重借用: http://theadmin.org/articles/2007/12/04/mephisto-trackback-library/

我修改了小幅我的目的:

require 'net/http' 
require 'uri' 

class Trackback 

    @data = { } 

    def initialize(link_id) 
    link = Link.find(link_id) 
    site = Link.website 

    if link.nil? 
     raise "Could not find link" 
    end 

    if link.created_at.nil? 
     raise "link not published" 
    end 

    @data = { 
     :title => link.name, 
     :excerpt => link.description, 
     :url => "http:://www.MyApp.org/links/#{link.to_param}/donations/new", 
     :blog_name => "My App" 
    } 
    end 

    def send(trackback_url) 
    u = URI.parse trackback_url 
    res = Net::HTTP.start(u.host, u.port) do |http| 
     http.post(u.request_uri, url_encode(@data), { 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8' }) 
    end 
    RAILS_DEFAULT_LOGGER.info "TRACKBACK: #{trackback_url} returned a response of #{res.code} (#{res.body})" 
    return res 
    end 

    private 

    def url_encode(data) 
    return data.map {|k,v| "#{k}=#{v}"}.join('&') 
    end 

end 

看起來像我發送鏈接成功到我的WordPress博客,但是當我看看引用鏈接上顯示的鏈接我得到這個:http://www.theurl.com/that/my/browser/iscurrentlypointing/at/http:://www.MyApp.org/links/# {link.to_param} /捐贈/新「

所有我想要的是這個長字符串的後半部分。不知道爲什麼當前位置在我的瀏覽器上偷偷溜進去。

我在我的兩個博客上試過這個,所以它似乎不是與我的wordpress安裝有關的問題。

更新:好的,這有點奇怪:我檢查了頁面源代碼,它顯示了正確的鏈接。然而,當我點擊它時,我會被引導到上面提到的怪異鏈接。這是一個WordPress的問題?

回答

1

哎呀!看起來這只是一個語法錯誤。手法高明的雙冒號

此行

url => "http:://www.MyApp.org/links/#{link.to_param}/donations/new" 

當然應該是這樣的

url => "http://www.MyApp.org/links/#{link.to_param}/donations/new", 
相關問題