我想從我的rails應用程序中取消用戶。但是,目前這不起作用。無法刪除用戶從欄杆
我的路線文件 -
# Root is the unauthenticated path
root 'sessions#unauth'
# Sessions URL
get 'sessions/unauth', to: 'sessions#unauth', as: :login
post 'sessions/login', as: :signin
delete 'sessions/logout', as: :logout
# Resourceful routes for articles
resources :articles
get '/interests', to: 'articles#my_interests', as: 'interests'
get '/destroy', to: 'users#destroy', as: 'destroy_user'
resources :users, only: [:create,:new,:update,:destroy,:edit]
然後,我有佈局文件夾裏面的html文件。
<li><%= link_to "De-activate User", destroy_user_path(current_user)%></li>
用戶將點擊取消激活的用戶按鈕,我期待採取措施進入我的用戶控制器。以下是我的UsersController.rb。
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user, only: [:edit, :destroy, :update]
before_action :check_valid, only: [:edit, :destroy, :update]
# DELETE /users/1
# DELETE /users/1.json
def destroy
log_out @user
@user.destroy
respond_to do |format|
format.html { redirect_to login_path, notice: 'user was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end
def check_valid
unless @user==current_user
redirect_to articles_path
end
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:first_name, :last_name, :email, :bio, :username, :password, :interest_list, :password_confirmation)
end
end
Rails給我錯誤的set_user方法。 錯誤 - 在@user = User.find(params [:id])找不到'user'的用戶
我無法理解這裏的問題是什麼?
我log_out方法 -
def log_out
session[:user_id] = nil
end
請張貼'log_out'方法 –
粘貼你的日誌 –
Rajarshi達斯 - 請立即檢查。 – coder05