title: When to use a virtual attribute or pass data in a hash in Rails 3
body: <p>In my application, I have a <code>Widget</code> model, a <code>Feature</code> model with a <strong>has_many through</strong> association by <code>WidgetFeature</code> table.  </p>
  
  <p>As per the requirements, when I am sending a WidgetFeature object, I should append the feature_name to it as well, for the given feature associated.<br>
  There are two ways of going at it:  </p>
  
  <ol>
  <li>While sending the object, do this:</li>
  </ol>
  
  <blockquote>
  <pre><code>widget_feature_object[:feature_name] = feature_name_value
  </code></pre>
  </blockquote>
  
  <p>and then I can access it in my controller or view, by <code>widget_feature_object[:feature_name]</code> because an object has (key, value) pairs, so I can add another too.  </p>
  
  <p>2 . Make <code>feature_name</code> a <strong>Virtual Attribute</strong> in <code>WidgetFeature</code> model, and then create <em>getter and setter methods</em> for it.  </p>
  
  <p>From what I know, that you should use virtual attributes when you want to create a different view different from the fields actually present in the model (e.g Full name = First name + Last name).<br>
  Does the same thing fits in here too?  </p>
  
  <p><strong>Also</strong>, does Rails do some caching on objects, that might get in useful when you use virtual attributes and not when I use the first approach?  </p>
  
  <p>What are the pros and cons of each approach and which one suits the best as per my requirements?
  Thanks a lot.</p>