Sessions controller in lesson


#1

In the sessions controller in the create method there is a portion I don't understand.

    session[:user_id] = @user.id
    redirect_to '/'
  else
    redirect_to 'login'
  end 
end

what does the '/' in redirect_to stand for. I know it redirects to the albums controller. But how are we acessing it using '/' Also is there a difference between get 'login' and get '/login' or post 'login' and post '/login'. Does the '/' added make any difference.


#2

Hi @fineboy1,

what does the '/' in redirect_to stand for

Type https://www.codecademy.com/ into your browser's URL bar. It takes you to the home page, since there's nothing after the slash (/) to indicate what page to go to on the codecademy.com domain. That line does the same thing as redirect_to root_url (or root_path).

is there a difference between get 'login' and get '/login' or post 'login' and post '/login'. Does the '/' added make any difference.

The slash doesn't make a difference in this case, but if you have a link on a page like:

<a href="about">About</a>

And you're currently on /contact, clicking the link will take you to /contact/about, when you actually want /about.

There's a difference between GET and POST methods too. GET is when you ask the server to send you information (like GET https://www.codecademy.com/), and POST is when you send the server information (like POST https://www.codecademy.com login[user]=zystvan login[password]=secret - that's not what the header actually looks like, I'm just trying to give you an idea)


#3

Thanks for clarifying


#4

This topic is solved.