How do I set a virtual attribute on an existing model?
<p>So I have a <code>User</code> model that has a <code>first_name</code> and <code>last_name</code> column.</p>

<p>I would like to create a new virtual attribute called <code>username</code>, that I can access even in my routes file.</p>

<p>I tried doing this:</p>

<pre><code>attr_accessor :username 

  # getter
  def username
    @username
  end

  # setter
  def username=(user)
    @username = "#{user.first_name}.#{user.last_name}"
  end
</code></pre>

<p>But when I try to set it, I get a wrong number of arguments error.</p>

<pre><code>[27] pry(main)&gt; u.username=(u)
ArgumentError: wrong number of arguments (1 for 0)
from     
[28] pry(main)&gt; u.username = u
ArgumentError: wrong number of arguments (1 for 0)
from 
</code></pre>

<p><code>u</code> is a valid <code>User</code> record.</p>

<p>Ideally, I would like to do two things. I would like to be able to check the <code>user.username</code> for all <code>User</code> objects in my DB and it should return per the above <code>setter</code> method.</p>

<p>How can I achieve this?</p>