I like the idea because I've also suffered with this problem before.

What about passing the class as the second argument like in serialize?

class Monkey < ActiveRecord::Base
    attr_virtual :birth_date, Date
end

On Thu, Jul 5, 2012 at 2:38 PM, Aleksey Magusev <[email protected]> wrote:

> Periodically i need to use *attr_accessor* in models, which will be used
> in views like *date_select*. In this case will be raised 
> error<https://github.com/rails/rails/blob/master/activerecord/lib/active_record/attribute_assignment.rb#L166>
>  because
> of klass 
> method<https://github.com/rails/rails/blob/master/activerecord/lib/active_record/attribute_assignment.rb#L171>
>  call
> for nil.
>
> What do you all think about adding attar_virtual method in ActiveModel to
> solve this problem?
>
> Variants:
> 1) Columns hash <https://gist.github.com/3055907>
> 2) Struct <https://gist.github.com/3055890>
> 3) Class <https://gist.github.com/3055931>
> and more.
>
> References:
>
> http://stackoverflow.com/questions/4971523/attr-accessor-for-a-date-and-problems-using-select-date
>
> http://stackoverflow.com/questions/5463337/in-rails-is-there-a-way-to-specify-a-type-youd-like-an-attr-accessor-to-be-an
> ...
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-core/-/73EswiuEVy0J.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-core?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to