Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have just completed this exercise as well, so I am by no means an expert; however, this is the code that has worked for me and passed all the tests:</p> <p>../app/views/sessions/new.html.erb</p> <pre><code>&lt;% provide(:title, "Sign in") %&gt; &lt;h1&gt;Sign in&lt;/h1&gt; &lt;div class="row"&gt; &lt;div class="span 6 offset 3"&gt; &lt;%= form_tag sessions_path do %&gt; &lt;%= label_tag :email %&gt; &lt;%= text_field_tag :email, params[:email] %&gt; &lt;%= label_tag :password %&gt; &lt;%= password_field_tag :password %&gt; &lt;%= submit_tag "Sign in", class: "btn btn-large btn-primary" %&gt; &lt;% end %&gt; &lt;p&gt;New User?&lt;%= link_to "Sign Up Now", signup_path %&gt; &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I also needed to change the ../app/controllers/sessions_contoller</p> <pre><code>class SessionsController &lt; ApplicationController def new end def create user = User.find_by_email(params[:email]) if user &amp;&amp; user.authenticate(params[:password]) session[:user] = user.id sign_in user redirect_to user else flash.now[:error] = 'Invalid email/password combination' render 'new' end end def destroy sign_out redirect_to root_path end end </code></pre> <p>Whilst this works, I'm not entirely sure why it does; if someone could explain why the changes in the controller are required it would be much appreciated. I know that this could be posed a s a separate question but it is closely related to OP and I'm sure we would both find it extremely useful in understanding not just how to get this to work but why it works this way. The following are the original view and controller files:</p> <p>Original 'form_for' new.html.erb:</p> <pre><code>&lt;% provide(:title, "Sign in") %&gt; &lt;h1&gt;Sign in&lt;/h1&gt; &lt;div class="row"&gt; &lt;div class="span6 offset3"&gt; &lt;%= form_for(:session, url: sessions_path) do |f| %&gt; &lt;%= f.label :email %&gt; &lt;%= f.text_field :email %&gt; &lt;%= f.label :password %&gt; &lt;%= f.password_field :password %&gt; &lt;%= f.submit "Sign in", class: "btn btn-large btn-primary" %&gt; &lt;% end %&gt; &lt;p&gt;New user? &lt;%= link_to "Sign up now!", signup_path %&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>and the original sessions_controller:</p> <pre><code>class SessionsController &lt; ApplicationController def new end def create user = User.find_by_email(params[:session][:email]) if user &amp;&amp; user.authenticate(params[:session][:password]) sign_in user redirect_to user else flash.now[:error] = 'Invalid email/password combination' render 'new' end end def destroy sign_out redirect_to root_path end end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload