joe
2008-Feb-29 12:37 UTC
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ilan Berci
2008-Feb-29 14:31 UTC
Re: cn w update the two tables under one action ...both are
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'' > > endInstead 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Bush
2008-Feb-29 15:31 UTC
Re: cn w update the two tables under one action ...both are
joe wrote:> @article = Category.newSo @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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---