Home>

I would like to use a helper to switch between the screen when logging in and the screen when not logged in in the header.

When processing when not done, if you write two link_to (new registration and login) in helper

Only the last one is displayed (only new registration in the example below),

Is there a way to display two?

I would appreciate it if you could tell me.

  def header_login
        if user_signed_in?
            link_to current_user.email, "/"
        else else
            link_to "login", new_user_session_path, class:'post'
            link_to "new registration", new_user_registration_path, class:'post'
        end
    end
  • Answer # 1

    The return value of method is the value of the last evaluated expression.
    So only the last one will be returned

    (link_to "login", new_user_session_path, class:'post' +
     link_to "new registration", new_user_registration_path, class:'post'
    ) .html_safe
    safe_join ([[
     link_to "login", new_user_session_path, class:'post',
     link_to "new registration", new_user_registration_path, class:'post'
     ])


    Etc.