Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## pattern desired
- anyone can create a Directory
- if its an admin user, automatically create a statistic object for the directory after its created
- ## unclear where to put what
- I was doing this all in the model with "after_create :add_statistic", which worked fine for all creations
- But now I want to only create a statistic for the directory if its an admin user.
- ## controllers/application.rb
- def admin?
- session[:password] == 'some_password'
- end
- ## models/directory.rb
- after_create :add_statistic #now needs to be done only for admins
- protected
- def add_statistic
- stat = statistics.create(
- :google_links => get_google_links,
- :yahoo_links => get_yahoo_links,
- :google_pages => get_google_pages,
- :yahoo_pages => get_yahoo_pages,
- :pagerank => get_pagerank
- )
- end
Add Comment
Please, Sign In to add comment