我的routes.rb文件中有以下设置:
INSERT INTO taxi(taxi_id) VALUES (@taxi_id)
但是我想添加更多的机构来限制基于db的我的机构专栏中的名字。我如何将其作为函数干净地添加到正则表达式而不是仅仅执行scope '(:institution)', institution: /acme/ do
等
/acme|acme1|acme2/
它在我的数据库已经创建时有效,但是如果我尝试运行:
scope '(:institution)', institution: Regexp.union(Institution.pluck(:custom_sign_up_name).compact) do
它告诉我该表在DB中不存在:
rake db:drop db:setup
我如何解决这个问题?我需要能够删除并重新创建要传递CI的数据库
答案 0 :(得分:0)
我设法通过处理异常来解决它:
class DynamicRouter
def self.load
institutions = retrieve_institutions_with_custom_sign_up_names
Rails.application.routes.draw do
scope '(:institution)', institution: institutions do
devise_scope :user do
get ':institution' => 'devise/sessions#new'
end
get 'omniauth/:provider' => 'omniauth#institution', as: :institution_omniauth
devise_for :users, skip: [:invitation, :omniauth_callbacks], controllers: { sessions: 'devise/sessions', registrations: 'devise/registrations' }
end
end
end
def self.reload
Rails.application.reload_routes!
end
private
def self.retrieve_institutions_with_custom_sign_up_names
Regexp.union(Institution.pluck(:custom_sign_up_name).compact)
rescue ActiveRecord::StatementInvalid
return ''
end