Burhan Gardezi
Burhan Gardezi

Reputation: 321

what is the better way to add conditional routing in rails

I have to change the route in a way that I need to have the original route as well as change the path of the route in a env is available. this is how I am thinking of doing

    
    custom_org = ENV['CUSTOM_ORG']&.downcase
    custom_org_pronoun = custom_org.pluralize
    if ! custom_org_pronoun.nil? && custom_org_pronoun.present?
      resources :organizations, only: %i[], path: custom_org_pronoun do
        resources :merge_users, only: %i[new create], path: '/merge-users'
      end
    end
    resources :organizations, only: %i[], path: plural_custom_org_pronoun do
      resources :merge_users, only: %i[new create], path: '/merge-users'
    end

the desired output I want is that the \organizations and (lets say custom_org = home) \homes both should work at the same time

Upvotes: 0

Views: 50

Answers (0)

Related Questions