this line
DailyTip.find_by_slug(tip[:slug]).persisted?
does not make much sense because find_by_slug will query the db and if something is found it will check whether it is already saved to the db. If nothing is found your code will break with:
undefined method `persisted?' for nil:NilClass
I think you meant to write something like this:;
if DailyTip.find_by(slug: tip[:slug])
puts "Video tip already created"
else
daily_tip = DailyTip.create! tip: tip[:tip]
day = ProgramDay.find_by_day(tip[:program_day])
day.update_attributes(daily_tip_id: daily_tip.id)
end
Finally, a lot depends on your app logic. I hope this helps a bit.