Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. 1. Question.count
  2. 2. Lingo.find(16)
  3. 3. Lingo.find_by_term("Linux"), Lingo.where(term: "Linux").first, Lingo.find_by(term: "Linux"), Lingo.where("term = ?", "Linux").first
  4. 4. Question.where(user_id: 67), User.find(67).questions
  5. 5. User.first(500).pluck(:last_name)
  6. 6.*question_count = Question.group(:user_id).count
  7. question_count.values.max
  8. question_count.select {|k, v| v == 10}
  9.  
  10. 7. Question.last.destroy
  11. 8. answers = Question.pluck(:answer_text)
  12. answer_length = answers.map {|x| x.length}
  13. Question.all.select {|q| q.answer_text.length == answer_length.max}
  14.  
  15. Question.order("LENGTH(answer_text) DESC").limit(1) (FOR JUST ONE)
  16. 9. User.where(subscribed: true)
  17. 10. User.where(subscribed: false).order(:created_at).pluck(:email)
  18. 11. Lingo.where("created_at < ?", '2017-01-01')
  19. 12. Question.first(55), Question.limit(55)
  20. 13. Question.last(105), Question.order(id: :desc).limit(105) *first one preserves ascending order*
  21. 14. Question.find(231).expert.first_name
  22. 15. User.create(first_name: "Some", last_name: "Guy", email: "someguy@gmail.com", password: "password", password_confirmation: "password")
  23. 16. User.create(first_name: "Some", last_name: "Guy", email: "someotherguy@gmail.com", password: "password", password_confirmation: "password", expert: true, expert_type: "Data Science")
  24. 17. COMING SOON
  25. 18. arr_q = Question.where(question_text: "")
  26. arr_q.each {|question| question.question_text = "string"; question.save}
  27. 19. User.create(first_name: "Some", last_name: "Guy", email: "someotherguy2@gmail.com", password: "password", password_confirmation: "password", expert: true, expert_type: "User Experience Design")
  28. User.find_by_expert_type("design").update_attributes(expert_type: "graphic design")
  29. 20. Question.where(user_id: 546).each {|q| q.destroy}
  30. User.find(546).destroy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement