我现在在我的用户控制器上使用设计,似乎无法摧毁我的用户。编辑,新的仍然工作。 Destroy仅重定向我以显示用户属性。
我的用户控制器:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
redirect_to users_path
else
render 'new'
end
end
def index
@users=User.all
end
def edit
@user = User.find(params[:id])
end
def destroy
@user = User.find(params[:id])
@user.destroy
redirect_to users_path
end
def delete
end
def update
@user = User.find(params[:id])
if @user.update_attributes(user_params)
redirect_to user_path(@user.id)
else
render 'edit'
end
end
def show
@user = User.find(params[:id])
end
private
def user_params
params.require(:user).permit(:name, :email, :password)
end
end
用户视图:
<h1>Users#index</h1>
<p>Find me in app/views/users/index.html.erb</p>
<table>
<tr>
<td>name</td>
<td>email</td>
<td>password</td>
</tr>
<% @users.each do |user| %>
<tr>
<td><%= link_to user.name, user_path(user.id) %></td>
<td><%= user.email %></td>
<td><%= user.password %></td>
<td><%= link_to "edit user", edit_user_path(user.id) %> </td>
<td><%= link_to "destroy user", user, method: :delete %> </td>
</tr>
<% end %>
</table>
是否与
有关<td><%= link_to "destroy user", user, method: :delete %> </td>
行?看来这就是给我带来最大麻烦的线。我正在使用设计,如果这是相关的,我也有问题试图解决它。
我的佣金路线:
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
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
PATCH /users/password(.:format) devise/passwords#update
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
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PATCH /posts/:id(.:format) posts#update
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
答案 0 :(得分:0)
因为您正在使用设计,所以它不适用于常规控制器。
您必须使用注册路径而不是用户路径:
<%= link_to "Delete User", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>