我无法将参数从我的关注点传递到Service对象。
它告诉我:
无法验证CSRF令牌的真实性。 //它将此显示为信息,因为我跳过了
ArgumentError(参数数量错误(给定0,应为1)):
app / services / task_manager / task_destroyer.rb:6:在“初始化”中
我认为我正确地传递了参数:
// production_controller.rb
skip_before_action :verify_authenticity_token
protect_from_forgery with: :null_session
def destroy
TaskManager::TaskDestroyer.new.destroy_task(params)
respond_to do |format|
format.json { render json: @tasks }
end
end
// app / services / task_manager / task_destroyer.rb
module TaskManager
class TaskDestroyer
def initialize(params)
@params = params
end
def destroy_task
// code of the method i call
end
end
end
答案 0 :(得分:2)
您传递不正确
TaskManager::TaskDestroyer.new(params).destroy_task
new
将其传递给类的initialize
方法