Ask A Question


You’re not receiving notifications from this thread.

Metaprogramming Virtual Attributes Discussion

Nice intro into metaprogramming and how concerns can be used.
I'm one of the fresh subscribers and have noticed one thing: no need to quit rails console to clear the console output. To save couple of seconds you can just press cmd + K in terminal (also from rails console) and you're good to continue.


Sweet! I figured there might be something to do that. I only ever clear the terminal in screencasts so I always forget to look that up. :)


One suggestion. Post references about related screencasts, gems etc in description please)


I have a model called Customer which belongs to a User. I am trying to implement a way for the Customer to have access to the attributes directly ( e.g.: Customer.first_name instead of having to write Customer.user.first_name ).
This is what I have so far:


after_initialize :set_user_properties,  if: { |c| c.user.present? }

def  set_user_properties
    # binding.pry
    c_columns = { |c| {  => c.type } }
    u_columns = { |c| {  => c.type } }.reject { |column| c_columns.include?(column) }.reduce,  :merge

    u_columns.each  do  |key, value|
        attribute key, value,  default:  self.user.try(key)
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,453+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.