Cn w update the two tables under one action ...both are in one to one relation

i hav tried this thng…but it s coming to the else part.

class Article < ActiveRecord::Base
belongs_to :category
end

class Category < ActiveRecord::Base
has_one :article
end

def update
@article = Category.new
@article.uploaded_data = (params[:article])
@article.article = Article.find(params[:id])
@article.article.tag_list = (params[:tag_list])
if @article.update_attributes(params[:article])
redirect_to :action => ‘show’, :id => @article
else
@categories = Category.find(:all)
render :action => ‘edit’

end

joe wrote:

def update
@article = Category.new
@article.uploaded_data = (params[:article])
@article.article = Article.find(params[:id])
@article.article.tag_list = (params[:tag_list])
if @article.update_attributes(params[:article])
redirect_to :action => ‘show’, :id => @article
else
@categories = Category.find(:all)
render :action => ‘edit’

end

Instead of update_attributes(), use update_attributes!() and then you
will be able to see the exception of why you weren’t able to save…

optionally, you can just check @article.errors

hth

ilan

joe wrote:

@article = Category.new

So @article is a Category. It may help to follow what is happening by
using more relevant variable names. Perhaps use @category to refer to a
category?

@article.uploaded_data = (params[:article])

What is params[:article] refering to? Does it come from a form editing
an article or is it just a text field which you’re setting to this
attribute of a Category object?

@article.article = Article.find(params[:id])
    @article.article.tag_list = (params[:tag_list])
   if @article.update_attributes(params[:article])

You’ve been carefully setting attributes of @article (a Category object)
and now you are going to overwrite those from params[:article] which
earlier looked like a text element (uploaded_data) but now is a hash of
Category object keys and values?

I suspect your problem is that you are trying to set this Category
object (@article) from an Article attribute hash and you probably want:

if @article.article.update_attributes(params[:article])

?
If so, then the confusion is probably due to calling your Category
object by the name @article