Hi, I am a very new to ruby on rails so please forgive me if someone has asked this before. I need to make a form with many checkboxes. Sometime ago I was using Coldfusion and I chanced upon this great article on how to store flags using binary numbers. http://cfdj.sys-con.com/read/41674.htm Just wondering if there is something similar in RubyOnRails that I can learn from and use. That rails have done it easier. Please note that I am very new to RubyOnRails. P.V.Anthony
Philip Hallstrom
2006-Jul-06 19:06 UTC
[Rails] Using Integers to Store Bits of Information
> I am a very new to ruby on rails so please forgive me if someone has asked > this before. > > I need to make a form with many checkboxes. Sometime ago I was using > Coldfusion and I chanced upon this great article on how to store flags using > binary numbers. > http://cfdj.sys-con.com/read/41674.htm > > Just wondering if there is something similar in RubyOnRails that I can learn > from and use. That rails have done it easier. > > Please note that I am very new to RubyOnRails.I don''t know of anything that will do this automatically, but you can certainly do it. I do it right now manually just by shifting bits around with <<. Works fine. -philip
Philip Hallstrom wrote:>> >> Please note that I am very new to RubyOnRails. > > I don''t know of anything that will do this automatically, but you can > certainly do it. I do it right now manually just by shifting bits > around > with <<. Works fine. > > -philipFixnums support some bit-wise opperations You can also store binary values explicitly: a = 0b01 a[n] returns the nth bit, where a[0] is the least significant bit See http://ruby-doc.org/core/classes/Fixnum.html for details Cheers -- Posted via http://www.ruby-forum.com/.
Use composition. Make a class that represents your flags as boolean attributes, then have it map those attributes to integers in any convenient way. Do yourself a favor and DON''T expose your flagging implementation. On Jul 6, 2006, at 11:27 AM, P.V.Anthony wrote:> Hi, > > I am a very new to ruby on rails so please forgive me if someone > has asked this before. > > I need to make a form with many checkboxes. Sometime ago I was > using Coldfusion and I chanced upon this great article on how to > store flags using binary numbers. > http://cfdj.sys-con.com/read/41674.htm > > Just wondering if there is something similar in RubyOnRails that I > can learn from and use. That rails have done it easier. > > Please note that I am very new to RubyOnRails. > > P.V.Anthony > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
On Friday, July 07, 2006, at 11:23 AM, Tom Mornini wrote:>Use composition. > >Make a class that represents your flags as boolean attributes, >then have it map those attributes to integers in any convenient >way. > >Do yourself a favor and DON''T expose your flagging implementation. > >On Jul 6, 2006, at 11:27 AM, P.V.Anthony wrote: > >> Hi, >> >> I am a very new to ruby on rails so please forgive me if someone > >>has asked this before. >> >> I need to make a form with many checkboxes. Sometime ago I was > >>using Coldfusion and I chanced upon this great article on how to > >>store flags using binary numbers. >> http://cfdj.sys-con.com/read/41674.htm >> >> Just wondering if there is something similar in RubyOnRails that I >>> can learn from and use. That rails have done it easier. >> >> Please note that I am very new to RubyOnRails. >> >> P.V.Anthony >> _______________________________________________ >> 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/railsI think there''s a ''acts_as_bitfield'' plugin somewhere. _Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.