Form_tag issue

Hi,

I below coded saved in
new.rhtml(C:\RubyForRails\railsapps\phonebook\app\views\phonenumber)
file and executed .
But while accessing getting below issue.

Add new phonenumber

<% form_tag '/create' do %>

PersonName: <%= text_field 'phonenumber', 'personname' %>

PhoneNumber: <%= text_field 'phonenumber', 'phnumber' %>

TypeOfPhoneNumber: <%= collection_select(:phonenumber,:typeofnumber_id,@names,:id,:typeofnumber) %>

Description
<%= text_area 'phonenumber', 'description' %>

<%= submit_tag "Create" %> <% end %> <%= link_to 'Back', {:action => 'list'} %>

***************************Error **************************

NoMethodError in Phonenumber#new

Showing app/views/phonenumber/new.rhtml where line #2 raised:

undefined method `^’ for “5”:String
Extracted source (around line #2):

1:

Add new phonenumber


2: <% form_tag ‘/create’ do %>
3:

PersonName:
4: <%= text_field ‘phonenumber’, ‘personname’ %>


5:

PhoneNumber:
RAILS_ROOT: C:/RubyForRails/railsapps/phonebook

Application Trace | Framework Trace | Full Trace
C:/RubyForRails/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb:46:in
block in secure_compare' C:/RubyForRails/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb:45:ineach’
C:/RubyForRails/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb:45:in
secure_compare' C:/RubyForRails/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb:28:inverify’
C:/RubyForRails/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/cookie_store.rb:156:in
unmarshal' C:/RubyForRails/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/cookie_store.rb:145:inload_session’
C:/RubyForRails/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:62:in
block in load!' C:/RubyForRails/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:70:instale_session_check!’
C:/RubyForRails/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:61:in
load!' C:/RubyForRails/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:28:in[]’
C:/RubyForRails/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:inform_authenticity_token’
C:/RubyForRails/railsapps/phonebook/app/views/phonenumber/new.rhtml:2:in
`_run_rhtml_app47views47phonenumber47new46rhtml’

***phonenumber_controller.rb
code

class PhonenumberController < ApplicationController
def list
@phonenumbers = Phonenumber.find(:all)
end

def new
@Phonenumber = Phonenumber.new
@names = Name.find(:all)
end

def create
@phonenumber = Phonenumber.new(params[:phonenumber])
if @phonenumber.save
redirect_to :action => ‘list’
else
@names = Name.find(:all)
render :action => ‘new’
end
end

end

Regards,
GRR

Rajeswar reddy Gaulla wrote:

Hi,

I below coded saved in
new.rhtml(C:\RubyForRails\railsapps\phonebook\app\views\phonenumber)
file and executed .
But while accessing getting below issue.

Add new phonenumber

<% form_tag '/create' do %>

PersonName: <%= text_field 'phonenumber', 'personname' %>

PhoneNumber: <%= text_field 'phonenumber', 'phnumber' %>

TypeOfPhoneNumber: <%= collection_select(:phonenumber,:typeofnumber_id,@names,:id,:typeofnumber) %>

Description
<%= text_area 'phonenumber', 'description' %>

<%= submit_tag "Create" %> <% end %> <%= link_to 'Back', {:action => 'list'} %>

***************************Error **************************

NoMethodError in Phonenumber#new

Showing app/views/phonenumber/new.rhtml where line #2 raised:

undefined method `^’ for “5”:String
Extracted source (around line #2):

1:

Add new phonenumber


2: <% form_tag ‘/create’ do %>
3:

PersonName:
4: <%= text_field ‘phonenumber’, ‘personname’ %>


5:

PhoneNumber:
RAILS_ROOT: C:/RubyForRails/railsapps/phonebook

Application Trace | Framework Trace | Full Trace
C:/RubyForRails/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb:46:in
block in secure_compare' C:/RubyForRails/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb:45:in each’
C:/RubyForRails/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb:45:in
secure_compare' C:/RubyForRails/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4/lib/active_support/message_verifier.rb:28:in verify’
C:/RubyForRails/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/cookie_store.rb:156:in
unmarshal' C:/RubyForRails/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/cookie_store.rb:145:in load_session’
C:/RubyForRails/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:62:in
block in load!' C:/RubyForRails/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:70:in stale_session_check!’
C:/RubyForRails/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:61:in
load!' C:/RubyForRails/lib/ruby/gems/1.9.1/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:28:in []’
C:/RubyForRails/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’
C:/RubyForRails/railsapps/phonebook/app/views/phonenumber/new.rhtml:2:in
`_run_rhtml_app47views47phonenumber47new46rhtml’

***phonenumber_controller.rb
code

class PhonenumberController < ApplicationController
def list
@phonenumbers = Phonenumber.find(:all)
end

def new
@Phonenumber = Phonenumber.new
@names = Name.find(:all)
end

def create
@phonenumber = Phonenumber.new(params[:phonenumber])
if @phonenumber.save
redirect_to :action => ‘list’
else
@names = Name.find(:all)
render :action => ‘new’
end
end

end

Regards,
GRR

Hi,

I found the root cause to this issue.

it occurring because of secure_compare method in
lib\ruby\gems\1.9.1\gems\activesupport-2.3.4\lib\active_support\message_verifier.rb

existing method in 2.3.4

  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

to come out of this issue use below method, if you want.

  def secure_compare(a, b)
    result = a.length ^ b.length
    for i in 0..99 # or some other constant
      result |= a[i].to_i ^ b[i].to_i
    end
    result == 0
  end

to know about issue, please visit:
https://rails.lighthouseapp.com/projects/8994/tickets/3144-undefined-method-for-string-ror-234