[メモ]Ubuntu1.9にruby 1.9.1-p243でRails 2.3.4を本を読みながら勉強中

若干、本の構成とは変えて rubyは1.9系で、 DBはMySQLにて作成。

まずは本のとおりに作成してみるが、エラーが発生

NoMethodError in Ex4s#index

Showing app/views/ex4s/index.html.erb where line #17 raised:

undefined method `^' for "8":String
Extracted source (around line #17):

14:     <%=h ex4.address %>
15:     <%= link_to 'Show', ex4 %>
16:     <%= link_to 'Edit', edit_ex4_path(ex4) %>
17:     <%= link_to 'Destroy', ex4, :confirm => 'Are you sure?', :method => :delete %>
18:   
19: <% end %>
20: 
RAILS_ROOT: /home/takao/learning/rails/Training

Application Trace | Framework Trace | Full Trace
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb:47: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/activesupport-2.3.4/lib/active_support/message_verifier.rb:45:in `secure_compare'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb:28:in `verify'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/cookie_store.rb:156:in `unmarshal'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/cookie_store.rb:145:in `load_session'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:62:in `block in load!'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:70:in `stale_session_check!'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:61:in `load!'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:28:in `[]'
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/request_forgery_protection.rb:102:in `form_authenticity_token'
(eval):2:in `form_authenticity_token'
/home/takao/learning/rails/Training/app/views/ex4s/index.html.erb:17:in `block in _run_erb_app47views47ex4s47index46html46erb'
/home/takao/learning/rails/Training/app/views/ex4s/index.html.erb:10:in `each'
/home/takao/learning/rails/Training/app/views/ex4s/index.html.erb:10:in `_run_erb_app47views47ex4s47index46html46erb'
/home/takao/learning/rails/Training/app/controllers/ex4s_controller.rb:7:in `index'

エラーが発生していると言われている「app/views/ex4s/index.html.erb」自体は、scaffoldで自動生成されたもので
手を入れていないし、ソースを見たところ問題が無さそう。

「active_support/message_verifier.rb」を見てみると、

    private
      # constant-time comparison algorithm to prevent timing attacks
      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

      def generate_digest(data)
        require 'openssl' unless defined?(OpenSSL)
        OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new(@digest), @secret, data)
      end
  end

「result |= a[i] ^ b[i]」で、Stringで^は使えないと怒られているようなので、
緊急避難的に、「result |= a[i].to_i ^ b[i].to_i」と型変換を入れることに。

これでやっと動きました。

Google グループ
ぐぐったら、同じところの事を書いているようだけど、英語なので(^^;;
とりあえずは放置で