I also tried
def create
@listing = Listing.find(params[:listing_id])
@flag = listing.flags.create(params[:flag])
@flag.user = authenticated_user
@flag.save
end
but that didn''t do the trick either. The odd thing is when I try
something similar in script/console, sometimes @listing.flags.size =1 after the
call to listing.flags.create and sometimes it remains at
0. I should also mention that the flag model uses the acts_as_tree
plugin in Rails 2.0, but does not use the counter_cache option of the
plugin.
On Dec 28, 6:36 pm, bigbanger
<bigbanger...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''ve got a has_many/belongs_to association between two Rails
models
> and I''m caching the child counter in the parent model via a
> counter_cache. When adding a child to the parent via the
''<<'' method
> of the parent, I was expecting the in-memory child counter in the
> parent to be updated, but it doesn''t appear as though it is. My
> controller code looks something like this:
>
> def create
> @flag = Flag.new(params[:flag])
> @flag.user = authenticated_user
> @listing = Listing.find(params[:listing_id])
> @listing.flags << @flag
> end
>
> If I add a call to @listing.save after adding the child to the parent,
> the in-memory counter is updated, but I didn''t think the call to
> ''save'' was necessary. Am I doing something wrong or is
this WAD?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---