Skip to main content
edited tags
Link
sepp2k
  • 9.1k
  • 2
  • 39
  • 51
Tweeted twitter.com/#!/StackCodeReview/status/46086281553383424
edited tags
Link
ssri
  • 247
  • 1
  • 4
Source Link
ssri
  • 247
  • 1
  • 4

Refactor Helper methods

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?