Sinatra Mongoid字符串无效UTF-8

时间:2010-10-08 00:49:55

标签: ruby sinatra mongoid

我写了这个小应用程序:

require 'rubygems'
require 'sinatra'
require 'bson'
require 'mongoid'

Mongoid.configure do |config|
  name = "articles"
  host = "localhost"
  config.master = Mongo::Connection.new.db(name)
  config.persist_in_safe_mode = false
end

class Article
  include Mongoid::Document

  field :title
  field :content
end

get '/' do
  @articles = Article.all
end

get '/show/:id' do
  @article = Article.find(params[:id])
end

get '/new' do
  haml :new
end

post '/create' do
  @article = Article.new(params['article'])
  if @article.save
    redirect '/'
  else
    redirect '/new'
  end  
end

当我发布包含“Test d'un articleenfrançais”内容的文章时,会发生以下错误

BSON::InvalidStringEncoding at /create String not valid UTF-8 

我如何解决此错误?

由于

1 个答案:

答案 0 :(得分:0)

这是Ruby 1.9和Sinatra的一个已知问题。等待Sinatra 1.1发布或使用github的Sinatra edge版本。