Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用方法调用在RubyonRails控制器中重定向_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 使用方法调用在RubyonRails控制器中重定向

Ruby on rails 使用方法调用在RubyonRails控制器中重定向,ruby-on-rails,ruby,Ruby On Rails,Ruby,这正在中断控制器文件的测试。由于某些原因,无法正确重定向: def edit redirect_if_nil(@user) end def redirect_if_nil(user) if user.nil? redirect_to :register_invalid_token, notice: "Your token was invalid" and return end end 替换: redirect_to :register_invalid_token, not

这正在中断控制器文件的测试。由于某些原因,无法正确重定向:

def edit
  redirect_if_nil(@user)
end

def redirect_if_nil(user)
  if user.nil?
    redirect_to :register_invalid_token, notice: "Your token was invalid" and return
  end
end
替换:

redirect_to :register_invalid_token, notice: "Your token was invalid" and return
致:


有两个错误。首先,
:register\u invalid\u token
不是有效的重定向选项。您应该传递散列选项以组成路由或路由路径

其次,
return
将返回
重定向(如果
),而不是控制器。因此它是无用的

假设
register\u invalid\u token\u path
是路由:

def edit
  redirect_if_nil(@user)
end

def redirect_if_nil(user)
  unless user
    redirect_to register_invalid_token_path, notice: "Your token was invalid"
  end
end

你能提供错误日志和控制器代码吗?
def edit
  redirect_if_nil(@user)
end

def redirect_if_nil(user)
  unless user
    redirect_to register_invalid_token_path, notice: "Your token was invalid"
  end
end