I am looking deeper into the login process with Sinatra.
Login.erb
<div id="flash" class="failure">
<h2> <%= flash[:failure] %> </h2>
</div>
<a href="/welcome">Go Back</a>
<% if @user.nil? == false %>
<% if @user.errors.any? %>
<%= erb 'shared/_error_messages'.to_sym %>
<form action="/users/signin" method="post">
<p> User Login</p>
<label> Email <input type="text" name="[:session][:email]"/> </label></br>
<label> Password <input type="password" name="[:session][:password]"/> </label></br>
<input type="submit" value="Log in">
</form>
<% end %>
<% else %>
<form action="/users/signin" method="post">
<p> User Login</p>
<label> Email <input type="text" name="[:session][:email]"/> </label></br>
<label> Password <input type="password" name="[:session][:password]"/> </label></br>
<input type="submit" value="Log in">
</form>
<% end %>
When I use a binding.pry to determine what happens when we submit the post request I see that I will get the following:
[1] pry(#<Sinatra::Application>)> params
{
":session" => {
":email" => "tasha@gmail.com",
":password" => "123"
}
}
I do know that I have a hash with the key-value pair.
I was wondering why do I need to put quotations around the symbols in the brackets instead of having it stand alone to pull the value out? Also, why if I named it without the double quotes why did it add the double quotes when I request the params in pry?
[2] pry(#<Sinatra::Application>)> params[:session]
nil
[3] pry(#<Sinatra::Application>)> params[":session"]
{
":email" => "tasha@gmail.com",
":password" => "123"
}
[4] pry(#<Sinatra::Application>)> params[:session][:email]
NoMethodError: undefined method `[]' for nil:NilClass
from (pry):31:in `block in <main>'
[5] pry(#<Sinatra::Application>)> params[":session"][":email"]
"tasha@gmail.com"
[6] pry(#<Sinatra::Application>)>