ruby on rails - How can I create_or_update in seeds.rb for translations? -


i have following in seeds.rb

os = orderstatus.find(1) os.translations.create(:status => "in aanmaak", :locale => "nl") os.translations.create(:status => "creating", :locale => "en") 

however creates doubles. tried create_or_update instead of create doesn't seem supported. using globalize3

based on comment following:

os = orderstatus.find(1) os.translations.where(locale: "nl").first_or_create.update_attributes(status: "in aanmaak") os.translations.where(locale: "en").first_or_create.update_attributes(status: "creating") 

i'm not sure if there's nicer way of writing this, create own method:

class translation < activerecord::base   def first_or_update(locale, status)     where(locale: locale).first_or_create.update_attributes(status: status)   end end  os.translations.first_or_update("en", "creating") 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -