Can somebody please explain more what this means? I know CC explained it, but found the explanation to be very brief. Hopefully a more elaborate explanation would help.
Hi Jay,
<%= form_for(:session, url: login_path) do |f| %>
says to the computer “Create me a form for the sessions
controller, and submit it to the URL login_path
which was defined in config/routes.rb
”
Also, a quick search brought up several documentation pages which looked helpful.
Thanks Zeke, I’m assuming create a form using the create method within the sessions controller? Still trying to grasp the login_path. Is the login path for this located in the views/sessions/new.html.erb file?
I’m assuming create a form using the create method within the sessions controller?
Correct.
Is the login path for this located in the views/sessions/new.html.erb file?
No:
login_path
which was defined inconfig/routes.rb
It’s the thing that says as: :login_path
(or something similar) in the routes.rb
file.
Nothing in my routes file says as: :login_path , below is how my routes file shows…
Rails.application.routes.draw do
root 'albums#index'
get 'albums' => 'albums#index'
get 'albums/new' => 'albums#new'
get 'albums/:id' => 'albums#show', as: :album
post 'albums' => 'albums#create'
get 'signup' => 'users#new'
resources :users
get '/login' => 'sessions#new'
post '/login' => 'sessions#create'
@jaydacoder In that case, something weird is going on, or it’s been a little too long since I went through this course
It seems to be an automatically created URL helper by Rails; I’m not sure where you would look to see the code for it.
@jaydacoder login_path refer to Post ‘/login’ in your routes
whenever you use a form_for helper in Rails, it will automatically use the POST variant of your routes
for more info https://stackoverflow.com/questions/24375454/whats-the-meaning-of-url-path-in-form-for