Interpolating an attribute's key before save
<p>I'm using Rails 4 and have an <code>Article</code> model that has  <code>answer</code>, <code>side_effects</code>, and <code>benefits</code> as attributes. </p>

<p>I am trying to create a <code>before_save</code> method that automatically looks at the side effects and benefits and creates links corresponding to another article on the site. </p>

<p>Instead of writing two virtually identical methods, one for side effects and one for benefits, I would like to use the same method and check to assure the attribute does not equal <code>answer</code>. </p>

<p>So far I have something like this:</p>

<pre><code>before_save :link_to_article

private 

def link_to_article
  self.attributes.each do |key, value|
    unless key == "answer" 
      linked_attrs = []
      self.key.split(';').each do |i|
        a = Article.where('lower(specific) = ?', i.downcase.strip).first
        if a &amp;&amp; a.approved?
          linked_attrs.push("&lt;a href='/questions/#{a.slug}' target=_blank&gt;#{i.strip}&lt;/a&gt;")
        else
          linked_attrs.push(i.strip)
        end
      end
      self.key = linked_attrs.join('; ')
    end
  end
end
</code></pre>

<p>but chaining on the key like that gives me an <code>undefined method 'key'</code>.</p>

<p>How can I go about interpolating in the attribute?</p>