2010-05-27 36 views
1

我在使用rails應用程序工作tumblr時遇到了一些問題。提交tumblr文章時出現400錯誤(ruby on rails)

這是代碼段,這導致一個400錯誤(這意味着有一個不正確的參數)

@postcontent = @post.content.gsub(/<\/?[^>]*>/, "") 

post = Tumblr::Post.create(:email => '[email protected]', :password => 'mypassword', :type => 'video', :embed 

=> @ post.video_html,:字幕=> @postcontent)

我檢查了API文檔並檢查了我的代碼和正在呈現的代碼內容,但它仍然不想工作。

有趣的是,它以前工作。它在一週前工作。 tumblr有什麼改變?

更新:我也發佈在github上的問題部分,並發現它只是與我的一個帖子中,這種方法不工作,我已經發送給tumblr好人。其他人遇到過這個問題嗎?

+0

任何人有任何想法呢? – 2010-06-18 04:24:02

回答

1

我已經做了這一點...

的人在這一發現的困難在這裏是一個解決方案。 首先,寶石本身出現了錯誤。一些代碼需要修改。 看看這個版本的寶石: http://github.com/mindreframer/tumblr

其次,作爲的tumblr允許HTML,我打電話控制器內消毒,使我的內容很好地格式化和清潔。

class PostsController < ApplicationController 
    include ActionView::Helpers::TextHelper 
    include ActionView::Helpers::SanitizeHelper 

def tumblrsubmit 
    tumblruser = Tumblr::User.new('[email protected]', 'validpass', false) 
    Tumblr.blog = 'blogname' 
    @post = Post.find(params[:id]) 
    begin 
    unless @post.movie_id.nil? #checks if there is a movie ID 
     @tags = @post.tags.join(', ') 
     post = Tumblr::Post.create(tumblruser, 
     :type => 'video', 
     :embed => @post.video_html , #fetches the stored embed code 
     :caption => "Read Full Article &amp; More at: <a href='http://www.mywebsite.com/posts/#{@post.slug}'>#{@post.title}</a> <p> </p>#{ActionController::Base.helpers.sanitize(@post.content)}", 
     :slug => @post.slug, 
     :tags => @tags) 
    else 
     post = Tumblr::Post.create(:tumblruser, :type => 'regular', :title => @post.title, :body => ActionController::Base.helpers.sanitize(@post.content), :slug => @post.slug) 
    end 
    @post.update_attributes(:tumbler_id => "#{post}") #updates the database with the new tumblr post id 
    flash[:notice] = "Successfully sent <strong>#{@post.title}</strong> to tumblr. with post id = #{post}" 
    rescue 
    flash[:error] = "You are unable to post <strong>#{@post.title}</strong> to tumblr at this time" 
    end 
    redirect_to :back 
    end 

end 

我知道這看起來好像很多,但它的確是工作。 希望這可以幫助其他任何人。

乾杯, Matenia