Created
August 8, 2011 23:43
-
-
Save azuby/1133057 to your computer and use it in GitHub Desktop.
Sign in form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sessions controller action: | |
def create | |
user = User.find_by_email(params[:email]) | |
if user && user.authenticate(params[:password]) | |
session[:user_id] = user.id | |
redirect_to root_url, :notice => "Successfully signed in." | |
else | |
flash.now.alert = "Invalid email or password." | |
@title = "Sign In" | |
render 'new' | |
end | |
end | |
this works: | |
<%= form_tag sessions_path do %> | |
<div class="field"> | |
<%= label_tag :email %> | |
<%= text_field_tag :email, params[:email] %> | |
</div> | |
<div class="field"> | |
<%= label_tag :password %> | |
<%= password_field_tag :password %> | |
</div> | |
<div class="actions"><%= submit_tag "Log in"%></div> | |
<% end %> | |
this doesn't: | |
<h1>Sign in</h1> | |
<%= form_for(:session, :url => sessions_path) do |f| %> | |
<div class="field"> | |
<%= f.label :email, "Email:" %><br /> | |
<%= f.text_field :email %> | |
</div> | |
<div class="field"> | |
<%= f.label :password, "Password:" %><br /> | |
<%= f.password_field :password %> | |
</div> | |
<div class="actions"> | |
<%= f.submit "Sign In" %> | |
</div> | |
<% end %> | |
<p>New user? <%= link_to "Sign up now!", signup_path %></p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment