Guest User

Untitled

a guest
May 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. ## pattern desired
  2.  
  3. anyone can create a Directory
  4. if its an admin user, automatically create a statistic object for the directory after its created
  5.  
  6. ## unclear where to put what
  7.  
  8. I was doing this all in the model with "after_create :add_statistic", which worked fine for all creations
  9.  
  10. But now I want to only create a statistic for the directory if its an admin user.
  11.  
  12. ## controllers/application.rb
  13. def admin?
  14. session[:password] == 'some_password'
  15. end
  16.  
  17. ## models/directory.rb
  18.  
  19. after_create :add_statistic #now needs to be done only for admins
  20.  
  21.  
  22. protected
  23. def add_statistic
  24. stat = statistics.create(
  25. :google_links => get_google_links,
  26. :yahoo_links => get_yahoo_links,
  27. :google_pages => get_google_pages,
  28. :yahoo_pages => get_yahoo_pages,
  29. :pagerank => get_pagerank
  30. )
  31. end
Add Comment
Please, Sign In to add comment