Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## View
- # From ThisController#this_action
- <%= selected(:controller => 'this_controller', :classes => 'box') %>
- => class="selected box"
- # From ThisController#this_action
- <%= selected(:controller => 'this_controller', :action => 'this_action', :classes => 'section blue') %>
- => class="section red"
- # From ThisController#this_action
- <%= selected(:controller => 'this_controller', :action => 'different_action', :classes => 'section blue') %>
- => class="section blue"
- ## Helper
- def current?(options = {})
- if !options[:action] and controller.controller_name == options[:controller]
- return true
- elsif !options[:controller] and controller.action_name == options[:action]
- return true
- elsif controller.controller_name == options[:controller] and controller.action_name == options[:action]
- return true
- else
- return false
- end
- end
- def selected(options = {})
- classes = options[:classes]
- status = current?(options) ? "selected" : nil
- classes = [status, classes].compact.join(" ")
- return " class=\"#{classes}\"" unless classes.empty?
- end
Add Comment
Please, Sign In to add comment