1

我正在尝试将 Datamapper 用作我的 Ruby/Padrino 应用程序的 ORM。要设置数据库连接,在 databse.rb 中,我有:

when :development then DataMapper.setup(:default, "mysql://db_user:dsfsdfs@localhost/my_app_development")

这工作很好。但我的要求是有复杂的密码,比如:

when :development then DataMapper.setup(:default, "mysql://db_user:Passw0rd#13@localhost/my_app_development")

这不起作用,我得到错误:

ruby/1.9.1/gems/addressable-2.2.8/lib/addressable/uri.rb:1179:in `port=': Invalid port number: "Passw0rd" (Addressable::URI::InvalidURIError)

我发现“#”字符有问题。然后我尝试这样做:

DataMapper.setup(:default, 
{
    :adapter => "mysql",
    :database => "my_app_development",
    :username => "db_user",
    :password => "Passw0rd#13",
    :host => "localhost"
})

当我这样做时,似乎 DM 完全忽略了哈希;当我跑步时

padrino rake db:create

它尝试以当前登录用户身份连接,而不是此处指定的用户名。解决方案?

4

2 回答 2

0

我想你仍然需要像下面这样声明它,以防你不是

when :development then
  DataMapper.setup(:default, 
  {
      :adapter => "mysql",
      :database => "my_app_development",
      :username => "db_user",
      :password => "Passw0rd#13",
      :host => "localhost"
  })
when :production then
  # rest of your code
end
于 2013-01-21T13:52:03.963 回答
0

明白了 - 关键:username应该是:user. 基本上,散列应该包含键Addressable::URI

于 2013-07-02T12:08:15.690 回答