Hello, In my database, I have a table "products" with attributes : - id - title ->string - desc -> text I use active record, but I don''t know why recover the type of this attribute with active record? I try attributes_before_type_cast but I don''t see the type Can you help me? Excuse for my english (I''am a young student french) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Richard Vincent wrote:> Hello, > > In my database, I have a table "products" with attributes : > - id > - title ->string > - desc -> text > > I use active record, but I don''t know why recover the type of this > attribute with active record? > > I try attributes_before_type_cast but I don''t see the type > > Can you help me? > > Excuse for my english (I''am a young student french) >Either of these should get you what you want. MyClass.columns_hash[''column_name''].type @instance_of_my_class.column_for_attribute(:column_name).type Although, I should mention that in nearly two years of developing in Rails professionally, I don''t think I''ve ever needed to retrieve this information in any of my apps. Are you sure that what you really want isn''t the ruby class of the value (eg. @instance.column_name.class ), or something else? -- http://www.5valleys.com/ http://www.workingwithrails.com/person/8078 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Richard Vincent
2008-Mar-04 12:52 UTC
Re: how can i know type of attribute with active record
Ok thanks for your example, it''s goog for my app Other question : In my database, I have a table "line_items" with attributes : - id -> integer - product_id -> integer and I have a foreign key (product-id references table product) It is possible to recover the class of attribute product_id? In my app I list object in my database (like phpMyAdmin) and if a foreign key I want to link to the object reference by this foreign key. For example, in "line_items", list object of this table and I want a link in "product_id" to this product I don''t know if it''s possible??? Jon Garvin wrote:> Richard Vincent wrote: >> I try attributes_before_type_cast but I don''t see the type >> >> Can you help me? >> >> Excuse for my english (I''am a young student french) >> > Either of these should get you what you want. > > MyClass.columns_hash[''column_name''].type > > @instance_of_my_class.column_for_attribute(:column_name).type > > > Although, I should mention that in nearly two years of developing in > Rails professionally, I don''t think I''ve ever needed to retrieve this > information in any of my apps. Are you sure that what you really want > isn''t the ruby class of the value (eg. @instance.column_name.class ), > or something else? > > -- > http://www.5valleys.com/ > http://www.workingwithrails.com/person/8078-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---