2009-10-01 86 views
1

我想测试一下,看看一个简单的带有数据库的铁路应用程序的运行是否可以正常工作,而且我正在运行问题。遇到Rails 2.3.4和Ruby 1.9.1的问题:未定义的方法`^'

这里是我采取的步骤:

> mkdir MyApp 
> cd MyApp 
> rails myapp 
    ... 
> rake db:create 
    ... 
> ruby script/generate scaffold user first_name:string last_name:string active:boolean 
    ... 
> rake db:migrate 
    ... 
> ruby script/server 
    ...  

从这里,我第一次打开http://localhost:3000/users页面将打开,然后我点击“新用户”。然后,我得到这个错误:

NoMethodError在用户#指数
显示应用程序/视图/布局/ users.html.erb其中第12行提出:

undefined method `^' for "7":String 

RAILS_ROOT:/用户/ lillq/MyApp的

/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb:46:in `block in secure_compare' 
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb:45:in `each' 
... 
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_view/base.rb:197:in `flash' 
/Users/lillq/MyApp/app/views/layouts/users.html.erb:12:in `_run_erb_app47views47layouts47users46html46erb' 
/Users/lillq/MyApp/app/controllers/users_controller.rb:7:in `index' 

所以,首先我认为版本可能不兼容,但有几个问题说1.9.1和rails是兼容的。

两个说,铁路和Ruby 1.9应该工作。

因此,这里是我运行的版本:

lillq:~/MyApp > ruby --version 
ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin10.0.0] 
lillq:~/MyApp > gem --version 
1.3.5 
lillq:~/MyApp > gem list 

*** LOCAL GEMS *** 

actionmailer (2.3.4) 
actionpack (2.3.4) 
activerecord (2.3.4) 
activeresource (2.3.4) 
activesupport (2.3.4) 
mysql (2.8.1) 
rack (1.0.0) 
rails (2.3.4) 
rake (0.8.7) 
sqlite3-ruby (1.2.5) 

所以从我可以在网上找到,所有的事情都告诉我,这应该运行。我错过了什么?

+0

我相信这与2.3.4版本打破了。为了测试,你可以运行2.3.3。现在这个问题已经得到解决,所以下一个Rails版本应该再次修复它! – NeilS 2009-10-01 06:43:03

回答

2

感谢statenjason链接到undefined method `^' for String - RoR 2.3.4它提供了解决方案。

该补丁的链接是here

从这个文件我把代码,并作出改变的文件:

的lib /红宝石/宝石/ 1.9.1 /宝石/的ActiveSupport-2.3.4/lib目录/ active_support/message_verifier.rb

message_verifier.rb secure_compare:

def secure_compare(a, b) 
    if a.length == b.length 
     result = 0 
     for i in 0..(a.length - 1) 
     result |= a[i]^b[i] 
     end 
     result == 0 
    else 
     false 
    end 
    end 

message_verifier.rb secure_compare:

def secure_compare(a, b) 
    if a.respond_to?(:bytesize) 
     # > 1.8.6 friendly version 
     if a.bytesize == b.bytesize 
     result = 0 
     j = b.each_byte 
     a.each_byte { |i| result |= i^j.next } 
     result == 0 
     else 
     false 
     end 
    else 
     # <= 1.8.6 friendly version 
     if a.size == b.size 
     result = 0 
     for i in 0..(a.length - 1) 
      result |= a[i]^b[i] 
     end 
     result == 0 
     else 
     false 
     end 
    end 
    end 

进行此更改后,问题就解决了。

2

我不得不在不久以前自己解决这个问题。在this thread开头的补丁(Jakub的不是hukl的)将解决该问题。讨论还解释了为什么问题首先存在,这是Ruby 1.9如何处理字节的行为差异。

相关问题