2010-05-27 63 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