Мое приложение ruby выдает ошибку, которая появилась внезапно. выдается ошибка NoMethodError в JobsDevsController # перечисление => неопределенный метод `user_id 'для nil: NilClass
Часть моего кода, которая выдает эту ошибку в моем контроллере, является
def is_authorised
redirect_to root_path, alert: "You don't have permission..." unless current_user.id == @job.user_id
end
Мой контроллер
class JobsDevsController < ApplicationController
before_action :set_jobs_dev , except: [:index, :new, :create, :show, :edit, :listing]
before_action :authenticate_user!, except: [:show, :listing]
before_action :is_authorised, only: [:listing, :budget, :description, :photo_upload, :location, :update, :show ]
# GET /jobs_devs
def index
@jobs_devs = JobsDev.all
end
# GET /jobs_devs/1
def show
end
# GET /jobs_devs/new
def new
@jobs_dev = current_user.jobs_devs.build
end
# def listing
# @jobs_dev = current_user.jobs_dev
# end
# GET /jobs_devs/1/edit
def edit
end
def budget
end
# POST /jobs_devs
def create
@jobs_dev = current_user.jobs_devs.build(jobs_dev_params)
if @jobs_dev.save!
redirect_to listing_jobs_dev_path(@jobs_dev), notice: 'Jobs dev was successfully created.'
else
render :new
end
end
# PATCH/PUT /jobs_devs/1
# def update
# if @jobs_dev.update(jobs_dev_params)
# redirect_to @jobs_dev, notice: 'Jobs dev was successfully updated.'
# else
# render :edit
# end
# end
def update
respond_to do |format|
if @jobs_dev.update(jobs_dev_params)
format.html { redirect_to @jobs_dev, notice: 'Post was successfully updated.' }
format.json { render :show, status: :ok, location: @jobs_dev }
else
format.html { render :edit }
format.json { render json: @jobs_dev.errors, status: :unprocessable_entity }
end
end
end
# DELETE /jobs_devs/1
def destroy
@jobs_dev.destroy
redirect_to jobs_devs_url, notice: 'Jobs dev was successfully destroyed.'
end
private
# Use callbacks to share common setup or constraints between actions.
def set_jobs_dev
@jobs_dev = JobsDev.find(params[:id])
end
def is_authorised
redirect_to root_path, alert: "You don't have permission..." unless current_user.id == @jobs_dev.user_id
end
# Only allow a trusted parameter "white list" through.
def jobs_dev_params
params.require(:jobs_dev).permit(:job_category, :job_type, :job_title, :job_description, :recurrence,
:budget, images: []
)
end
end
Пожалуйста, вы можете помочь с этим Senario