1

I have several forms in the same view, and it seems that they are conflicting with each other. I have a form that is supposed to call the reveal action in the users controller but instead it is calling the logins action in the user controller.

Here is my config/routes.rb:

get "logins" => 'users#logins', :as => 'logins'
delete "logins" => 'users#deletelogin', :as => 'logins'
post 'logins' => 'users#addlogin', :as => 'add_login'
get "logins" => 'users#search', :as => 'search'
get "logins" => 'users#reveal', :as => 'reveal'

Here is the button that is linking to the wrong action:

<td><%= button_to "Reveal", { :controller => :users, :action => 'reveal', :id => login.id }, method: :get, :class => 'btn' %></td>

This is the html that is rendering:

<td><form action="/logins?id=24" class="button_to" method="post"><div><input class="btn" type="submit" value="Reveal" /><input name="authenticity_token" type="hidden" value="POKdWunwvaKQHb+Mzj/3UrG0xIbKPqELy4n3VGqGrxU=" /></div></form></td>
4

1 回答 1

2

All three get methods map to the /logins url, so the behaviour is expected.

The first part in the hash used in the get method defines the actual path that will be used in the url. You'll have to do something like:

get "logins" => 'users#logins', :as => 'logins'
get "search" => 'users#search', :as => 'search'
get "reveal" => 'users#reveal', :as => 'reveal'

to get the desired effect.

于 2013-01-19T03:16:40.287 回答