2014-05-12 75 views
1

您可以指向我的任何良好的资源,展示如何将Sql Server连接到Rails应用程序(Windows 7)?错误与rails服务器命令

我也做了迄今为止以下内容: rails new simple_cms –d sqlserver

gem install bundle

rails s

最后一个命令后

,引发此错误:

C:\Sites\s_cms>rails s 
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.1.1/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method': undefined method `add_order!' for class `Class' (Name 
Error) 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.1.1/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method_chain' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb:14:in `singletonclass' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb:12:in `inc 
luded' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb:145:in `in 
clude' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb:145:in `<t 
op (required)>' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter.rb:3:in `require' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter.rb:3:in `<top (required)>' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/activerecord-sqlserver-adapter.rb:1:in `require' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/activerecord-sqlserver-adapter.rb:1:in `<top (required)>' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `require' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `block (2 levels) in require' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `each' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `block in require' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `each' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `require' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.6.1/lib/bundler.rb:132:in `require' 
     from C:/Sites/s_cms/config/application.rb:7:in `<top (required)>' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:79:in `require' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:79:in `block in server' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `tap' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:76:in `server' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!' 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>' 
     from bin/rails:4:in `require' 
     from bin/rails:4:in `<main>' 

PS:如果我使用sqlite作为数据库系统,我能够成功启动网络服务器(无错误)。这可能意味着我的导轨安装没有任何问题。我猜我可能需要添加某物到database.yml或写入数据库用户和密码的地方。但是,sqlite3不需要怎么做? 我也发现这个资源,但不知道如果仍然适用(它指的是rails 2.0,而我使用rails 4.1.1)http://rubyrailsandwindows.blogspot.de/2008/03/rails-2-and-sql-server-2008-on-windows_24.html - 我试过的一些东西,但不适用。 在此先感谢。

后来编辑:我也试着rails s编辑database.yml中(从config文件夹)之后,包含:

development: 
    adapter: sqlserver 
    encoding: unicode 
    database: cms 
    pool: 5 
    username: guest1 
    password: pwd1234%^&^ 
test: 
    adapter: sqlserver 
    encoding: unicode 
    database: cms 
    pool: 5 
    username: guest1 
    password: pwd1234%^&^ 
production: 
    adapter: sqlserver 
    encoding: unicode 
    database: cms 
    pool: 5 
    username: guest1 
    password: pwd1234%^&^ 

(当然,我也曾经创建了一个名为分贝CMS,并增加了一个用户调用指定的密码guest1虚拟机,然后确信德凭据工作连接到从我的本地SQL Server本身)

模拟-ING网络连接数据库这个新的动作,我收到了类似的错误如上后:

C:\Sites\simple_cms>rails s 
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-.1.1/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method': undefined method `add_order!' for class `Class' (Name Error) 
     from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-4.1.1/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method_chain' 
     ............... 

回答

2

这是activerecord-sqlserver-adapter的已知错误。它正在努力,但任何修补程序尚未合并成一个里程碑。

看来解决办法刚才是改变你的Gemfile有:问题的

gem 'activerecord-sqlserver-adapter', git: 'https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.git' 

细节here并修复它是here的努力。

+0

谢谢,格雷姆。我按照你的建议编辑了gemfile,然后再次运行'rails s'。它促使我做一个'bundle install' - 在我尝试运行它之后,我得到:'提取https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.git 致命的:无法访问'https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapt er.git /':无法连接到github.com:443;没有错误 重试git克隆“https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.gi t”“C:/Ruby193/lib/ruby/gems/1.9.1/cache/bundler/git/activerecord-sqlserver-adapter-a19f0 dc7902 .....' – Samy

+0

这是否可以再次因为代理?我认为我摆脱了后,我设置HTTP_PROXY环境变量,如下所示:http:// stackoverflow。 com/questions/23607571/set-proxy-for-rubygems。我不知道如何强制bundle安装使用代理(语法??)运行,或者甚至是这个问题。奇怪的是,我能够连接通过在浏览器中输入这个地址https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.git,为什么我认为它可能是一个代理服务器的事情。 – Samy

+1

很可能是你的代理。有一个有效的.gemspec所以它应该工作。考虑到你可以访问仓库,你可能需要把它作为一个zip文件(除非你可以'git clone')并在本地构建它。把它放在某个地方,然后在该目录中运行'gem build activerecord-sqlserver-adapter.gemspec',然后运行'gem install <刚建好的gem的名称>' –