8

I' m working on a rails app. using gem tire as a bond for elasticsearch. in a multistep form I would like to index at the end of the procedure.

is there a way of skipping indexing on create.

guess: Post.create( :indexing => false ) or whatever

or in tire config say : only index Post with attribute :published set to true

Hope I made myself clear. thanks in advance for your answers.

Cheers.

  • ok i guess I found out myself... don'tf look at the timestamps please... In the indexed model you can add: after_save do update_index if published == true end Hope it'll help some future lazy folks ok i guess I found out myself... don'tf look at the timestamps please... In the indexed model you can add: after_save do update_index if published == true end Hope it'll help some future lazy folks – Stan Bienaives Mar 06 '12 at 16:23
  • 2
    Do not "include Tire::Model::Callbacks" in your model if you use this method (cf. https://github.com/karmi/tire/issues/486). – danlee Dec 04 '12 at 21:34
  • 1
    @Stan - be sure to write up an answer and mark it as accepted. Nothing wrong with answering your own question! – Dave S. Mar 15 '13 at 02:10

1 Answers1

0

re: your answer above, after_save is called on create too so a better, more general answer to your question (i think) would be to make sure not to include Tire::Model::Callbacks in your model then

after_create :my_callback

def my_callback
  false
end
concept47
  • 30,257
  • 12
  • 52
  • 74
  • just be careful here because after_save fires on create too, so if you're using that you'll have to figure out a way to make sure it doesn't fire on create as well. – concept47 May 25 '13 at 19:32