addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1launch-new-window--smalllight-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [ruby-112] questions about tableless column

From: Alex B.
Sent on: Thursday, December 16, 2010 4:08 PM
I am seeing this issue pop up all the time when developers erroneously
assume that a model, or a resource, equals a database table. Nothing could
be farther from the truth. A resource MAY be persisted as a table that is
implemented in a RDBMS, but that's not always the case.

So the attr_accessor technique submitted below is the way to go.

On Thu, 16 Dec[masked]:17:49 -0500, bob stiles
<[address removed]> wrote:
> Seems like this is way overkill here.
> 
> Why not do something more like:
> 
> class Post < ActiveRecord::Base
> ������ attr_accessor :terms_of_use
> ������ validates_acceptance­_of :terms_of_use, :accept => true, :message =>
> "You must accept the terms of use"
>  end
> 
> On Thu, Dec 16, 2010 at 2:58 PM, Owen Ou  wrote:
>  Hi all,
> 
>  I have a question about ActiveRecord hope any of you can help me a bit.
> Thanks in advance :).
> 
>  I have a ActiveRecord model which has a boolean field to indicate
whether
> the use has accepted the license. I don't want to create a database
column
> related to that but I would like it to consume all the validation stuff
> provided by ActiveRecord. There are lots of solutions on the web but all
> of them are focusing on tableless model, while my model also have other
> fields corresponding to table columns. Here is what I come up with:
> https://gist.githu...­ [2].
> 
>  This solution seems pretty verbose and I am wondering whether there are
> better ones out there.
> 
>  Thanks,
>  Owen
> 
>  --
>  Please Note: If you hit "REPLY", your message will be sent to everyone
on
> this mailing list ([address removed] [3])
>  http://www.meetup...­ [4]
>  This message was sent by Owen Ou ([address removed] [5]) from Vancouver
> Ruby / Rails Meetup Group.
>  To learn more about Owen Ou, visit his/her member profile:
> http://www.meetup...­ [6]
>  To unsubscribe or to update your mailing list settings, click here:
> http://www.meetup...­ [7]
>  Meetup, PO Box 4668 #37895 New York, New York[masked] |
> [address removed] [8]
> 
>  --
>  Please Note: If you hit "REPLY", your message will be sent to EVERYONE
on
> this mailing list ([address removed] [9])
>  This message was sent by bob stiles ([address removed]) from
> Vancouver Ruby / Rails Meetup Group [10].
>  To learn more about bob stiles, visit his/her member profile [11]
>  To unsubscribe or to update your mailing list settings, click here [12]
> 
>   Meetup, PO Box 4668 #37895 New York, New York[masked] |
> [address removed]  
> 
> Links:
> ------
> [1] mailto:[address removed]
> [2] https://gist.githu...­
> [3] mailto:[address removed]
> [4] http://www.meetup...­
> [5] mailto:[address removed]
> [6] http://www.meetup...­
> [7] http://www.meetup...­
> [8] mailto:[address removed]
> [9] mailto:[address removed]
> [10] http://www.meetup...­
> [11] http://www.meetup...­
> [12] http://www.meetup...­

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy