[英]Rails route path inside as hash value
I'm trying to define constant REDIRECT_DEFINITIONS
with application paths as a key.我正在尝试使用应用程序路径作为键来定义常量
REDIRECT_DEFINITIONS
。 This constant is inside of shared controller:此常量在共享 controller 内部:
# frozen_string_literal: true
class SignupBaseController < ApplicationController
REDIRECT_DEFINITIONS = {
test_results: {
new: edit_users_experience_level_path(@current_user),
create: edit_users_experience_level_path(@current_user),
},
experience_levels: {
edit: new_users_identity_check_path,
},
"users/identity_checks": {
new: root_path,
},
default: request.referrer || root_path,
}.freeze
But I'm getting an error:但我收到一个错误:
undefined method `edit_users_experience_level_path' for SignupBaseController:Class
EDIT:编辑:
routes.rb:路线.rb:
namespace :users do
resource :dashboard, only: :show
resource :identity_check, only: %i[new create show]
resources :experience_levels, only: %i[edit update]
end
Include url_helpers in controllers as below, so that you can have access to all the routes/url of the application.如下在控制器中包含 url_helpers,以便您可以访问应用程序的所有路由/url。
# frozen_string_literal: true
class SignupBaseController < ApplicationController
include Rails.application.routes.url_helpers
REDIRECT_DEFINITIONS = {
test_results: {
new: edit_users_experience_level_path(@current_user),
create: edit_users_experience_level_path(@current_user),
},
experience_levels: {
edit: new_users_identity_check_path,
},
"users/identity_checks": {
new: root_path,
},
default: request.referrer || root_path,
}.freeze
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.