Bryan Duxbury
2006-Apr-16 23:37 UTC
[Rails] "Cannot convert String to Integer" after using association
So, I''ve written a partial that does some stuff with a given instance of my class "entity". Entity is ActiveRecord. I''m able to retrieve all sorts of data from an @entity, until I do something like: <% for @attribute in @entity.attributes %> <div id="attribute_<%= @attribute.id %>"> <%= render(:partial => ''attribute'') %> </div> <% end %> After which point, any attempt on my part to retrieve data from @entity ( for instance <%= @entity.id %> results in: cannot convert String into Integer The stack trace is: c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations/association_proxy.rb:75:in `[]'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations/association_proxy.rb:75:in `send'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations/association_proxy.rb:75:in `method_missing'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations/has_many_association.rb:90:in `method_missing'' (eval):1:in `id'' #{RAILS_ROOT}/app/views/main/_entity.rhtml:27 #{RAILS_ROOT}/app/views/main/index.rhtml:30 #{RAILS_ROOT}/app/views/main/index.rhtml:29:in `each'' #{RAILS_ROOT}/app/views/main/index.rhtml:29 This is really starting to tick me off. I had a workaround in which I retrieved all the important information before I used an association, but that won''t let me retrieve more than one type of associated information. Help? -- Posted via http://www.ruby-forum.com/.
Pete Yandell
2006-Apr-17 00:51 UTC
[Rails] "Cannot convert String to Integer" after using association
Brian, Can you include the actual code for _entity.rhtml, given that''s where your error is happening? Cheers, Pete Yandell http://9cays.com On 17/04/2006, at 9:37 AM, Bryan Duxbury wrote:> So, I''ve written a partial that does some stuff with a given > instance of > my class "entity". Entity is ActiveRecord. I''m able to retrieve all > sorts of data from an @entity, until I do something like: > > <% for @attribute in @entity.attributes %> > <div id="attribute_<%= @attribute.id %>"> > <%= render(:partial => ''attribute'') %> > </div> > <% end %> > > After which point, any attempt on my part to retrieve data from > @entity > ( for instance <%= @entity.id %> results in: > > cannot convert String into Integer > > The stack trace is: > > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ > active_record/associations/association_proxy.rb:75:in > `[]'' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ > active_record/associations/association_proxy.rb:75:in > `send'' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ > active_record/associations/association_proxy.rb:75:in > `method_missing'' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ > active_record/associations/has_many_association.rb:90:in > `method_missing'' > (eval):1:in `id'' > #{RAILS_ROOT}/app/views/main/_entity.rhtml:27 > #{RAILS_ROOT}/app/views/main/index.rhtml:30 > #{RAILS_ROOT}/app/views/main/index.rhtml:29:in `each'' > #{RAILS_ROOT}/app/views/main/index.rhtml:29 > > > This is really starting to tick me off. I had a workaround in which I > retrieved all the important information before I used an association, > but that won''t let me retrieve more than one type of associated > information. > > Help? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Mark Van Holstyn
2006-Apr-17 01:36 UTC
[Rails] "Cannot convert String to Integer" after using association
<%= @entity.id.to_s %> On 4/16/06, Pete Yandell <pete@notahat.com> wrote:> > Brian, > > Can you include the actual code for _entity.rhtml, given that''s where > your error is happening? > > Cheers, > > Pete Yandell > http://9cays.com > > On 17/04/2006, at 9:37 AM, Bryan Duxbury wrote: > > > So, I''ve written a partial that does some stuff with a given > > instance of > > my class "entity". Entity is ActiveRecord. I''m able to retrieve all > > sorts of data from an @entity, until I do something like: > > > > <% for @attribute in @entity.attributes %> > > <div id="attribute_<%= @attribute.id %>"> > > <%= render(:partial => ''attribute'') %> > > </div> > > <% end %> > > > > After which point, any attempt on my part to retrieve data from > > @entity > > ( for instance <%= @entity.id %> results in: > > > > cannot convert String into Integer > > > > The stack trace is: > > > > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ > > active_record/associations/association_proxy.rb:75:in > > `[]'' > > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ > > active_record/associations/association_proxy.rb:75:in > > `send'' > > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ > > active_record/associations/association_proxy.rb:75:in > > `method_missing'' > > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/ > > active_record/associations/has_many_association.rb:90:in > > `method_missing'' > > (eval):1:in `id'' > > #{RAILS_ROOT}/app/views/main/_entity.rhtml:27 > > #{RAILS_ROOT}/app/views/main/index.rhtml:30 > > #{RAILS_ROOT}/app/views/main/index.rhtml:29:in `each'' > > #{RAILS_ROOT}/app/views/main/index.rhtml:29 > > > > > > This is really starting to tick me off. I had a workaround in which I > > retrieved all the important information before I used an association, > > but that won''t let me retrieve more than one type of associated > > information. > > > > Help? > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Mark Van Holstyn mvette13@gmail.com http://lotswholetime.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060417/edbce17c/attachment.html
Bryan Duxbury
2006-Apr-17 03:25 UTC
[Rails] Re: "Cannot convert String to Integer" after using associati
Mark Van Holstyn wrote:> <%= @entity.id.to_s %>Believe me, I tried that. Besides, you can''t even print out the id or any text, no matter the format. Below is the code of _entity.rthml. The line that starts to loop for attributes will always fail. I hope someone finds something I missed. <div id="entity_<%= @entity.id %>" class="table_div" style="width: 100px; height: 50px" table="<%= @entity.name %>" onClick="tableClick(''entity_<%= @entity.id %>'');"><div class="drag_handle" onMouseDown="makeDraggable(''entity_<%= @entity.id %>'');" onMouseUp="makeUnDraggable();" > <%= @entity.name %> </div> <script language="JavaScript" type="text/javascript"> <!-- var temp = new Array(); temp.push(''<%= @entity.name %>''); temp.push(''entity_<%= @entity.id %>''); temp.push(new Array()); tables.push(temp); //--> </script> <div style="font-style: italic; border-top: 1px gray solid; border-bottom: 1px gray solid"> Attributes </div> <div id="entity_<%= @entity.id %>_attributes"> <% for @attribute in @entity.attributes %> <div id="attribute_<%= @attribute.id %>"> <%= render(:partial => ''attribute'') %> </div> <% end %> </div> <div style="font-style: italic; border-top: 1px gray solid; border-bottom: 1px gray solid"> Relations </div> <div id="entity__relations"> <% for @relation in @entity.relations %> <%= @relation.id %> <% end %> </div> </div> -- Posted via http://www.ruby-forum.com/.
Pete Yandell
2006-Apr-17 06:48 UTC
[Rails] Re: "Cannot convert String to Integer" after using associati
I''m betting something is broken in your attributes association. Can you post your entity and attribute models, and the schemas for their respective tables? On 17/04/2006, at 1:25 PM, Bryan Duxbury wrote:> <div id="entity_<%= @entity.id %>" > class="table_div" > style="width: 100px; height: 50px" > table="<%= @entity.name %>" > onClick="tableClick(''entity_<%= @entity.id %>'');" >> > <div class="drag_handle" > onMouseDown="makeDraggable(''entity_<%= @entity.id %>'');" > onMouseUp="makeUnDraggable();" >> > <%= @entity.name %> > </div> > > <script language="JavaScript" type="text/javascript"> > <!-- > var temp = new Array(); > temp.push(''<%= @entity.name %>''); > temp.push(''entity_<%= @entity.id %>''); > temp.push(new Array()); > tables.push(temp); > //--> > </script> > <div style="font-style: italic; border-top: 1px gray solid; > border-bottom: 1px gray solid"> > Attributes > </div> > <div id="entity_<%= @entity.id %>_attributes"> > <% for @attribute in @entity.attributes %> > <div id="attribute_<%= @attribute.id %>"> > <%= render(:partial => ''attribute'') %> > </div> > <% end %> > </div> > <div style="font-style: italic; border-top: 1px gray solid; > border-bottom: 1px gray solid"> > Relations > </div> > <div id="entity__relations"> > <% for @relation in @entity.relations %> > <%= @relation.id %> > <% end %> > </div> > </div>
Christian Klauser
2006-Apr-17 10:33 UTC
[Rails] Re: "Cannot convert String to Integer" after using associati
Mark Van Holstyn wrote:> <%= @entity.id.to_s %>You could replace this line with `<%= @entity.class.name %>` and tell us, what you get. #id is a method that returns the internal ruby id of an object represented by an integer. Maybe @entity is not an ActiveRecord... -- Posted via http://www.ruby-forum.com/.
Bryan Duxbury
2006-Apr-17 13:47 UTC
[Rails] Re: Re: "Cannot convert String to Integer" after using assoc
Pete Yandell wrote:> I''m betting something is broken in your attributes association. Can > you post your entity and attribute models, and the schemas for their > respective tables?class Attribute < ActiveRecord::Base belongs_to :entity end class Entity < ActiveRecord::Base has_many :attributes has_many :relations, :class_name => "Relation", :foreign_key => "entity1_id" has_many :incoming_relations, :class_name => "Relation", :foreign_key => "entity2_id" end The schema is mundane. There''s a table for each model, with ids and other fields. The data types of all those things are correct. I checked to make sure the key field of Entity was an integer, and it is. -- Posted via http://www.ruby-forum.com/.
Justin Forder
2006-Apr-17 15:48 UTC
[Rails] Re: Re: "Cannot convert String to Integer" after using assoc
Bryan Duxbury wrote:> Pete Yandell wrote: >> I''m betting something is broken in your attributes association. Can >> you post your entity and attribute models, and the schemas for their >> respective tables? > > class Attribute < ActiveRecord::Base > belongs_to :entity > end > > class Entity < ActiveRecord::Base > has_many :attributes > has_many :relations, > :class_name => "Relation", > :foreign_key => "entity1_id" > > has_many :incoming_relations, > :class_name => "Relation", > :foreign_key => "entity2_id" > end > > The schema is mundane. There''s a table for each model, with ids and > other fields. The data types of all those things are correct. I checked > to make sure the key field of Entity was an integer, and it is. >Bryan, you have chosen a name that clashes with Rails naming. An ActiveRecord instance uses an ''attributes'' hash to hold the state of its attributes, and this has public accessors (attributes, attributes=). regards Justin
Bryan Duxbury
2006-Apr-17 17:06 UTC
[Rails] Re: Re: Re: "Cannot convert String to Integer" after using a
Justin Forder wrote:> Bryan Duxbury wrote: >> has_many :attributes >> other fields. The data types of all those things are correct. I checked >> to make sure the key field of Entity was an integer, and it is. >> > > Bryan, you have chosen a name that clashes with Rails naming. > > An ActiveRecord instance uses an ''attributes'' hash to hold the state of > its attributes, and this has public accessors (attributes, attributes=). > > regards > > JustinHot damn. That would make sense, wouldn''t it. Guess I''ll have to rename. Thanks. -- Posted via http://www.ruby-forum.com/.