我已经在Sinatra中使用Datamapper验证,但是当尝试使用 flash [:error] 显示它们时,我不断收到被括号和引号括起来的错误。
Ex:[“已经收到电子邮件”]
%w{sinatra haml data_mapper bcrypt sinatra/flash}.each { |gem| require gem }
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db")
class User
include DataMapper::Resource
property :id, Serial
property :email, String, :length => 255, :unique => true
property :password, String, :length => 255
property :password_salt, String, :length => 255
attr_accessor :password, :password_confirmation
validates_format_of :email, :as => :email_address
validates_confirmation_of :password
end
enable :sessions
get '/signup' do
haml :signup
end
post '/signup' do
@user = User.new(:email => params[:email], :password => params[:password],
:password_confirmation => params[:password_confirmation],
:password_salt => BCrypt::Engine.generate_salt)
if @user.save
redirect '/'
else
flash[:error] = @user.errors.full_messages # here is the problem (I think)
redirect '/signup'
end
end
DataMapper.auto_upgrade!
和signup.haml
%h1 Sign up here!
- if flash[:error]
%p= flash[:error] ## Shortened for brevity (didn't include forms)
我已经在@ user.errors.full_messages上尝试了所有内容,展平,to_s等,但似乎没有删除括号和引号。
这实际上是gem sinatra-flash的问题吗?
答案 0 :(得分:3)
怎么样
@user.errors.full_messages.join(",")