I have two helper methods that return li for view with the li for current view having id as selected.
def get_li(a)
li = "<li"
li += ' id=selected' if (a[:controller] == params[:controller] && a[:action] == params[:action])
li += ">" + link_to(a[:text], { :controller => a[:controller], :action => a[:action]}) + "</li>"
end
def get_tab_options
if (params[:controller] == 'sessions' || params[:controller] == 'users')
[{:text => "Login", :controller => 'sessions', :action => 'new'},
{:text => "Sign Up", :controller => 'users', :action => 'new'}]
elsif (params[:controller] == 'meetings')
[{:text => "Meetings List", :controller => 'meetings', :action => 'index'},
{:text => "Create Meeting", :controller => 'meetings', :action => 'new'},
{:text => "Running Meetings", :controller => 'meetings', :action => 'monitor'}]
end
end
And the view file has
%ul
-get_tab_options.each do |a|
= get_li(a)
How can I write this better?