1
我正在关注rails中的教程和beggienr,在access_controller.rb中 它给了我错误:路由错误 没有路由匹配[POST]“/ access/login”!Rails 4,attemt_login失败
def attempt_login
if params[:username].present? && params[:password].present?
found_user = AdminUser.where(:username => params[:username]).first
if found_user
authorized_user = found_user.authenticate(params[:password])
end
end
if authorized_user
# TODO: mark user as logged in
flash[:notice] = "You are now logged in."
redirect_to(:action => 'index')
else
flash[:notice] = "Invalid username/password combination."
redirect_to(:action => 'login')
end
end
login.html.erb
<% @page_title = "Admin Login" %>
<div class="login">
<%= form_tag access_path do %>
<table>
<tr>
<td><%= label_tag :username %></td>
<td><%= text_field_tag :username %></td>
</tr>
<tr>
<td><%= label_tag :password %></td>
<td><%= password_field_tag :password %></td>
</tr>
<tr>
<td> </td>
<td><%= submit_tag("Log In") %></td>
</tr>
</table>
<% end %>
</div>
这里是我的路,我觉得问题应该是在这里,但我不知道如何解决它 的routes.rb
get 'login', to: 'access#create'
get 'access/login', to: 'access#create'
resources :access do
member do
get "login"
post "login"
get "logout"
post "logout"
get 'attempt_login'
end
end
谢谢,这个问题解决了,现在给我另一个路线ing错误,:没有路由匹配{:action =>“login”,:controller =>“access”}。 – Amir 2014-09-06 17:49:35
@Amir更新了我的答案。我也没有看到使用职位成员路线的目的 – Mandeep 2014-09-06 18:07:51
@ Mandeeo,我将其更改为您的代码,并且我得到了另一个错误:ActionController :: UrlGenerationError在AccessController中#create 没有路由匹配{:action =>“登录“,:controller =>”access“} – Amir 2014-09-06 18:31:46