我写了这个小应用程序:
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
我如何解决此错误?
由于
答案 0 :(得分:0)
这是Ruby 1.9和Sinatra的一个已知问题。等待Sinatra 1.1发布或使用github的Sinatra edge版本。