Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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 Rails路由中的重定向_Ruby On Rails_Ruby_Routes - Fatal编程技术网

Ruby on rails Rails路由中的重定向

Ruby on rails Rails路由中的重定向,ruby-on-rails,ruby,routes,Ruby On Rails,Ruby,Routes,我的rails应用程序中的路由如下所示: resources :users, only: :show 例如,现在我想重定向到当具有sended id的用户不存在时,以及当具有sended id的用户存在时,重定向到。使用routes约束是否可以做到这一点?routes是指表示url、方法的一部分的字符串与控制器中的操作之间的简单匹配。实现您的目标的最佳方法是在控制器中使用before\u action。范例 class UsersController < ApplicationCon

我的rails应用程序中的路由如下所示:

  resources :users, only: :show

例如,现在我想重定向到当具有sended id的用户不存在时,以及当具有sended id的用户存在时,重定向到。使用routes约束是否可以做到这一点?

routes是指表示url、方法的一部分的字符串与控制器中的操作之间的简单匹配。实现您的目标的最佳方法是在控制器中使用
before\u action
。范例

class UsersController < ApplicationController
  before_action :authenticate_user, only: [:show]

  def show
    ...
  end

  private

  def authenticate_user
    redirect_to some_other_path unless id_correct?
  end
end
class UsersController
路由是指表示url、方法和控制器内操作的一部分的字符串之间的简单匹配。实现您的目标的最佳方法是在控制器中使用
before\u action
。范例

class UsersController < ApplicationController
  before_action :authenticate_user, only: [:show]

  def show
    ...
  end

  private

  def authenticate_user
    redirect_to some_other_path unless id_correct?
  end
end
class UsersController
路由是指表示url、方法和控制器内操作的一部分的字符串之间的简单匹配。实现您的目标的最佳方法是在控制器中使用
before\u action
。范例

class UsersController < ApplicationController
  before_action :authenticate_user, only: [:show]

  def show
    ...
  end

  private

  def authenticate_user
    redirect_to some_other_path unless id_correct?
  end
end
class UsersController
路由是指表示url、方法和控制器内操作的一部分的字符串之间的简单匹配。实现您的目标的最佳方法是在控制器中使用
before\u action
。范例

class UsersController < ApplicationController
  before_action :authenticate_user, only: [:show]

  def show
    ...
  end

  private

  def authenticate_user
    redirect_to some_other_path unless id_correct?
  end
end
class UsersController