1

我在让 tumblr 在 Rails 应用程序中工作时遇到了一些问题。

这是导致 400 错误的代码片段(意味着存在不正确的参数)

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

post = Tumblr::Post.create(:email => 'valid@email', :password => 'mypassword', :type => 'video', :embed

=> @post.video_html, :caption => @postcontent)

我检查了 API 文档并检查了我的代码和正在呈现的代码内容,但它仍然不想工作。

有趣的是它以前工作过。大约一周前它还在工作。tumblr 有什么改变吗?

更新:我也在 github 的问题部分发布了这个,发现只有我的一篇帖子这种方法不起作用,我已经把它发给了 tumblr 的好人。其他人遇到过这个问题吗?

4

1 回答 1

1

我已经解决了...

对于任何在这方面遇到困难的人来说,这是一个解决方案。首先,gem 本身存在错误。一些代码需要修改。查看此版本的 gem:http: //github.com/mindreframer/tumblr

其次,由于 Tumblr 允许使用 html,我在控制器中调用 sanitize 以使我的内容具有良好的格式和干净。

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

def tumblrsubmit
    tumblruser = Tumblr::User.new('valid@email', '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

我知道这看起来很多,但它确实有效。希望这对其他人有帮助。

干杯,马特尼亚

于 2010-08-10T02:17:59.010 回答