title: create_or_update method in rails
body: <pre><code>if ClassName.exists?(["id = ?", self.id])
    object = ClassName.find_by_name(self.name)
    object.update_attributes!( :street_address =&gt; self.street_address,
      :city_name =&gt; self.city_name,
      :name =&gt; self.org_unit_name,
      :state_prov_id =&gt; self.state_prov_id,
      :zip_code =&gt; self.zip_code)
  else
    ClassName.create! :street_address =&gt; self.street_address,
      :city_name =&gt; self.city_name,
      :federalid =&gt; self.federalid,
      :name =&gt; self.org_unit_name,
      :state_prov_id =&gt; self.state_prov_id,
      :zip_code =&gt; self.zip_code
  end
  </code></pre>
  
  <p>I have code like this. I would like to improve it so that it uses a method, something like create_or_update.</p>
  
  <pre><code>    ClassName.create_or_update_by_name(:name =&gt; self.name,
      :street_address =&gt; self.street_address,
      :city_name =&gt; self.city_name,
      :federalid =&gt; self.federalid,
      :name =&gt; self.org_unit_name,
      :state_prov_id =&gt; self.state_prov_id,
      :zip_code =&gt; self.zip_code)
  </code></pre>
  
  <p>If the <code>name</code> exists in the database then it should update that object otherwise it should create a new object.</p>
  
  <p>Is there is any method that exists that I can do this with?</p>