在Datamapper.setup中指定复杂密码

时间:2013-01-18 07:21:33

标签: ruby database datamapper padrino

我正在尝试将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

它尝试以当前登录用户身份进行连接,而不是此处指定的用户名。溶液

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

知道了 - 密钥:username应为:user。基本上,哈希应该包含Addressable::URI

所理解的键