在我们的Rails 4.2
应用中,某些dynamic routes
存储在表格中,并在从表格中检索后添加到routes.rb
中。在routes.rb
中它是:
some_routes = find_config_const('some_route')
eval(some_routes) if some_routes.present?
以下是some_routes
的示例:
member do
get :event_action
patch :submit
patch :stamp
patch :pay
get :wf_edit
patch :wf_edit_result
end
改变结构后,现在我们面临一个问题。问题是会话变量session[:token]
被添加到find_config_const
作为搜索约束,如下所示:
some_routes = find_config_const('some_route', session[:token])
eval(some_routes) if some_routes.present?
由于session
中没有routes.rb
,因此find_config_const
会在wrong number of argument
时返回错误。基本上我们需要找到一种方法将session[:token]
的值传递给routes.rb
,或者找到另一种方法将some_routes
添加到路由表中。 token
对于一个应用程序是唯一的,可以将其定义为常量。关于如何在我们的案例中做动态路线的任何想法/建议?感谢。