Update: As it turned out I have a very similar situation in some
controller I'm just writing, so I just committed a small tweak to
make it less noisy:

   def update
     params[:document][:topic_ids] ||= []
     @document = Document.find(params[:id])
 
     # this will call ferret_update after the block, if the block evals
     # to true (which is the case when save succeeds). as a bonus, it
     # also returns the value returned by the block so we can use it in 
     # the if statement :-)
     if @document.disable_ferret(:index_when_true) {
          @topics = (params[:topics] or []).collect { |item| item.to_i }
          @document.attributes = params[:document]
          @document.topic_ids = @topics
          @document.save
        }
       flash[:notice] = 'Document was successfully updated.'
       redirect_to :action => 'show', :id => @document
     else
       render :action => 'edit'
     end
   end


the method name 'disable_ferret' doesn't fit this usage pattern that
nice, I'm open to suggstions ;-)

cheers,
Jens

On Thu, Nov 30, 2006 at 06:21:12PM +0100, Jens Kraemer wrote:
> On Thu, Nov 30, 2006 at 06:00:58PM +0100, Matthew Planchant wrote:
> > I got this working by disabling ferret for a block like this:
> 
> glad to hear :-)
> 
> >   def update
> >     params[:document][:topic_ids] ||= []
> >     @document = Document.find(params[:id])
> > 
> >     @document.disable_ferret do
> >       @topics = (params[:topics] or []).collect { |item| item.to_i }
> >       @document.attributes = params[:document]
> >       @document.topic_ids = @topics
> >       @document.save
> >     end
> > 
> 
> imho it would be better to not call update_attributes in this place, as
> you already saved the document inside the block above.  It's one line
> more for the explicit call to ferret_update but should save you one
> update call to your DB.
> 
> so instead of this:
> >     if @document.update_attributes(params[:document])
> 
> this should work, too:
> 
>       if @document.valid?     
>         @document.ferret_update
> >       flash[:notice] = 'Document was successfully updated.'
> >       redirect_to :action => 'show', :id => @document
> >     else
> >       render :action => 'edit'
> >     end
> >   end
> 
> you could even store the return value from the save call inside the
> block and use that in the if statement...
> 
> Jens
> 
> 
> -- 
> webit! Gesellschaft für neue Medien mbH          www.webit.de
> Dipl.-Wirtschaftsingenieur Jens Krämer       [EMAIL PROTECTED]
> Schnorrstraße 76                         Tel +49 351 46766  0
> D-01069 Dresden                          Fax +49 351 46766 66
> _______________________________________________
> Ferret-talk mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/ferret-talk
> 

-- 
webit! Gesellschaft für neue Medien mbH          www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer       [EMAIL PROTECTED]
Schnorrstraße 76                         Tel +49 351 46766  0
D-01069 Dresden                          Fax +49 351 46766 66
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to