我在这个 [question] 中部分解决了相同的情况:Problems with routes.rb
现在我的“/users/index”中有两个表单,例如登录表单和注册表单。我在 users_controller、post_login 和 post_registration 中创建了两个不同的操作,并通过简单的重定向到另一个页面,但是如果我单击按钮,它会给我同样的错误:没有路由匹配 [POST] "/users"
这是我的 routes.rb 代码
Mysite::Application.routes.draw do
controller :home do
get 'login' => :index
post 'login' => :create
end
resources :users, :only => [:index] do
get 'login' => :index
post 'login' => :post_login
get 'registration' => :index
post 'registration' => :post_registration
collection do
post 'post_login'
post 'post_registration'
end
end
# get "/users" => 'users#index'
# post "/users" => 'users#post_login'
get "home/index"
get "home/create"
get "home/show"
get "private/index"
get "users/index"
get "users/post_login"
get "users/post_registration"
end
虽然在这里我的form_registration ...
<%= form_tag do %>
<table>
<tr>
<td>
<%= text_field_tag :name, params[:name] %>
</td>
</tr>
<tr>
<td>
<%= password_field_tag :password, params[:password] %>
</td>
</tr>
<tr>
<td>
<%= submit_tag "Registration" %>
</td>
</tr>
<% end %>
</table>
...和form_login
<%= form_tag do %>
<table>
<tr>
<td>
<%= text_field_tag :name, params[:name] %>
</td>
</tr>
<tr>
<td>
<%= password_field_tag :password, params[:password] %>
</td>
</tr>
<tr>
<td>
<%= submit_tag "Login" %>
</td>
</tr>
<% end %>
<tr>
<td>
<%= link_to 'Registrazione', '/users/index' %>
</td>
</tr>
</table>
问题出在哪里?