Note that there are some explanatory texts on larger screens.

plurals
  1. POrails:how to verify what kind of user log in?
    text
    copied!<p>I'm a freshman in programming .This is my solution,but it can't log in.Always show 'Invalid email/password combination'.How to mend my code?And if there are some good web to learn rails ? Thanks </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.label :type %&gt; &lt;%= f.radio_button :type, 1, :checked =&gt; true %&gt; Student &lt;%= f.radio_button :type, 2 %&gt; Teacher &lt;%= f.submit "Sign in", class: "btn btn-large btn-primary" %&gt; &lt;% end %&gt; &lt;p&gt;New students? &lt;%= link_to "Sign up now!", signup_path %&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Session Controller:</p> <pre><code>class SessionsController &lt; ApplicationController def new end def create if [:type] == 1 user = User.find_by_email(params[:session][:email].downcase) if user &amp;&amp; user.authenticate(params[:session][:password]) redirect_to user #sign_in user # Sign the user in and redirect to the user's show page. else flash.now[:error] = 'Invalid email/password combination' render 'new' end else teacher = Teacher.find_by_email(params[:session][:email].downcase) if user &amp;&amp; user.authenticate(params[:session][:password]) redirect_to teacher #sign_in user # Sign the user in and redirect to the user's show page. else flash.now[:error] = 'Invalid email/password combination' render 'new' end end end def destroy sign_out redirect_to root_url end def signed_in_user unless signed_in? flash[:notice] = "Please sign in" redirect_to signin_url end 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