Forum: Ruby on Rails Updating model with has_one association - do not want to update associated model

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
55f6daf7813641a0cfb30150031c48d9?d=identicon&s=25 Josh (Guest)
on 2008-12-23 05:15
(Received via mailing list)
I have two classes: Article and Update.  When I try to update an
Article, it is NOT saving the instance, but is only saving the
associated Update object (which is valid).

class Article < ActiveRecord::Base
  has_one :update, :as => :content, :dependent => :destroy
end

class Update < ActiveRecord::Base
  belongs_to :content, :polymorphic => true, :readonly => true
end

class ArticlesController < ApplicationController
  def update
    @article = Article.find(params[:id])

    if @article.update_attributes(params[:article])
      flash[:notice] = 'Article was successfully updated.'
      redirect_to(@article)
    else
      render :action => 'edit'
    end
  end
end

When I check my log; however, you can see that only the Update object
was updated, not the Article object.  Any thoughts on why?  I haven't
done much with Rails 2.2, but this is not the behavior I remember from
earlier versions.

Thanks,
Josh
This topic is locked and can not be replied to.