Why doesn't this helper work?

So I'm cleaning up my views at the moment, and thought it'd be nice to create a couple of helpers, one that shows links if the user is logged in, and one that shows another set of links if they're not logged in.

Anyways, this is the code:

  def logged_in_links     if logged_in?         link_to 'New Highlight', new_highlight_path         link_to 'Logout?', logout_path         link_to 'Profile »', @current_user.login     end   end

I'm sure I'm making a rudimentary mistake (take into account I am a beginner), but whenever I execute the helper method only the last link shows up, and if I remove the last link than it's the new last link that displays etc.

What am I doing wrong? :slight_smile:

Hello, only results of the last statement executed are returned. You have to do something like

def logged_in_links html = ‘’ if logged_in? html += link_to ‘New Highlight’, new_highlight_path html += link_to ‘Logout?’, logout_path html += link_to ‘Profile »’, @current_user.login end html end

Ah, okay. Thanks for the hlep.

Gintautas Šimkus wrote: