我正在尝试实现登录表单,但我的路由似乎是错误的。当身份验证失败时,应用程序会重定向到 subdomain.domain.com/login,但它应该只再次呈现登录页面(仅 subdomain.domain.com 没有“/login”)。
意见/登录/index.html
<%= form_tag(check_login_path, :method => "post") do %>
... form fields
<% end %>
路线.rb
constraints(Subdomain) do
match '/' => 'login#index', :as => :login
match '/login' => 'login#check', :as => :check_login
match '/dashboard' => 'dashboard#index', :as => :dashboard
end
登录控制器.rb
class LoginController < ApplicationController
def index
# some index logic
end
def check
# authenticate with mite.yo.lk account login
Mite.account = params[:domain]
Mite.authenticate(params[:email], params[:password])
if Mite.validate
redirect_to dashboard_path
else
flash[:error] = "not valid"
render :template => 'login/index'
end
end
end