Ruby on rails 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
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