-1

私の問題は、レールヘルパーがユーザーモデル User に対して間違ったリンクを生成することです

<%= link_to "delete", user_registration_path(user), :method => :delete, :confirm => "You sure?" %>

次の URL を生成します:whatever.com/users.1

私のroutes.rb:

put "rooms/:id/close" => "rooms#close", :as => "close_room"

devise_for :users, path_names: {sign_in: "login", sign_out: "logout"},
controllers: {omniauth_callbacks: "omniauth_callbacks"}
get "home/index"

resource :user do
  # Route GET /user/tandem
  get 'tandem', :on => :collection
  get 'practice', :on => :collection

end

root :to => 'home#index'

resources :rooms
match '/party/:id', :to => "rooms#party", :as => :party, :via => :get
match '/users/find', :to => "users#find", :as => :find_users, :via => :get
# Sample resource route (maps HTTP verbs to controller actions automatically):
match '/users/edit/:id', :to => "users#edit", :as => :edit_user, :via => :get
resources :users, only: [:index ,:show, :edit, :update]

ルビー「1.9.3」、「レール」、「3.2.13」、デバイス(2.2.4)を使用しています。また、編集アクションでも発生します。編集:私のルートファイルは

 close_room PUT      /rooms/:id/close(.:format) rooms#close

 new_user_session GET      /users/login(.:format)                 devise/sessions#new
 user_session POST     /users/login(.:format)                 devise/sessions#create
 destroy_user_session DELETE   /users/logout(.:format)
 devise/sessions#destroy
 user_omniauth_authorize GET|POST /users/auth/:provider(.:format)
 omniauth_callbacks#passthru {:provider=>/facebook/}
 user_omniauth_callback GET|POST /users/auth/:action/callback(.:format) omniauth_callbacks#(?-mix:facebook)
 user_password POST     /users/password(.:format)              devise/passwords#create
 new_user_password GET      /users/password/new(.:format)          devise/passwords#new
 edit_user_password GET      /users/password/edit(.:format)         devise/passwords#edit
                     PUT      /users/password(.:format)                   devise/passwords#update
 cancel_user_registration GET      /users/cancel(.:format)                devise/registrations#cancel
 user_registration POST     /users(.:format)                       devise/registrations#create
 new_user_registration GET      /users/sign_up(.:format)               devise/registrations#new
edit_user_registration GET      /users/edit(.:format)                  devise/registrations#edit
                     PUT      /users(.:format)                       devise/registrations#update
                     DELETE   /users(.:format)                       devise/registrations#destroy
          home_index GET      /home/index(.:format)                  home#index
         tandem_user GET      /user/tandem(.:format)                 users#tandem
       practice_user GET      /user/practice(.:format)               users#practice
                user POST     /user(.:format)                        users#create
            new_user GET      /user/new(.:format)                    users#new
           edit_user GET      /user/edit(.:format)                   users#edit
                     GET      /user(.:format)                        users#show
                     PUT      /user(.:format)                        users#update
                     DELETE   /user(.:format)                        users#destroy
                root          /                                      home#index
               rooms GET      /rooms(.:format)                       rooms#index
                     POST     /rooms(.:format)                       rooms#create
            new_room GET      /rooms/new(.:format)                   rooms#new
           edit_room GET      /rooms/:id/edit(.:format)              rooms#edit
                room GET      /rooms/:id(.:format)                   rooms#show
                     PUT      /rooms/:id(.:format)                   rooms#update
                     DELETE   /rooms/:id(.:format)                   rooms#destroy
               party GET      /party/:id(.:format)                   rooms#party
          find_users GET      /users/find(.:format)                  users#find
               users GET      /users(.:format)                       users#index
                     POST     /users(.:format)                       users#create
                     GET      /users/new(.:format)                   users#new
                     GET      /users/:id/edit(.:format)              users#edit
                     GET      /users/:id(.:format)                   users#show
                     PUT      /users/:id(.:format)                   users#update
                     DELETE   /users/:id(.:format)                   users#destroy

4

2 に答える 2

-1

とのルートを削除resource :userして移動します。tandempracticeresources :users

/user/tandemこのようなルートの使用を維持したい場合は、

resource :user, only => [] do
  #tandem and practice routes as existing
end`

また、ユーザー リソースのルート宣言に :delete を追加する必要があります。

resources :users, only: [:index ,:show, :edit, :update, :delete]

link_tousers_pathlikeに変更します

link_to 'Destroy', users_path(user), method: :delete, data: { confirm: 'Are you sure?' }

于 2013-11-11T13:08:57.487 に答える