这是我的 SessionsController
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by_email(params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
# Sign the user in and redirect to the user's show page.
sign_in user
redirect_to user
else
flash.now[:error] = 'Invalid email/password combination' # Not quite right!
render 'new'
end
end
def destroy
end
结尾
这是 routes.rb
resources :sessions, only: [:new,:create,:destroy]
以及新视图和销毁视图的各自路线。
这是新的.html.erb
<% provide(:title , "Sign in")%>
<div id="signin_page" class="hero-unit container-fluid">
<h1>Sign In</h1>
<div class="row span6">
<%= simple_form_for :sessions, url: '/sessions', html: {:class=> 'form-horizontal'} do |f| %>
<%= f.input :email, label: "Email", placeholder: "Enter email",required: true%>
<%= f.input :password, label: "Password", placeholder: "Enter Password", required: true%>
<p id="signin_button"><%= f.button :submit, "Sign in", class: "btn btn-large btn-primary span2" %>
New user? <%=link_to "Sign up now!", '/signup'%></p>
<% end %>
</div>
错误就像。
我要实现的是,成功/失败的登录应该使用 Flash 消息呈现各自的视图。 我哪里错了。我是 ROR 的新手