Guest User

Untitled

a guest
Apr 26th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. ## View
  2.  
  3. # From ThisController#this_action
  4. <%= selected(:controller => 'this_controller', :classes => 'box') %>
  5. => class="selected box"
  6.  
  7. # From ThisController#this_action
  8. <%= selected(:controller => 'this_controller', :action => 'this_action', :classes => 'section blue') %>
  9. => class="section red"
  10.  
  11. # From ThisController#this_action
  12. <%= selected(:controller => 'this_controller', :action => 'different_action', :classes => 'section blue') %>
  13. => class="section blue"
  14.  
  15.  
  16. ## Helper
  17.  
  18. def current?(options = {})
  19. if !options[:action] and controller.controller_name == options[:controller]
  20. return true
  21. elsif !options[:controller] and controller.action_name == options[:action]
  22. return true
  23. elsif controller.controller_name == options[:controller] and controller.action_name == options[:action]
  24. return true
  25. else
  26. return false
  27. end
  28. end
  29.  
  30. def selected(options = {})
  31. classes = options[:classes]
  32. status = current?(options) ? "selected" : nil
  33. classes = [status, classes].compact.join(" ")
  34. return " class=\"#{classes}\"" unless classes.empty?
  35. end
Add Comment
Please, Sign In to add comment