简体   繁体   中英

Rails elsif block for Rails.env

I want to redirect user depends on environment. URLs for staging and production are in rails credentials, to avoid specs error I had to add new_session_path(resource_name) when environment is not staging or production. I've got below elsif block:

    protected

    def after_confirmation_path_for(resource_name)
      if Rails.env.staging?
        Rails.application.credentials.confirmation_account_url_staging
      elsif Rails.env.production?
        Rails.application.credentials.confirmation_account_url_production
      else
        new_session_path(resource_name)
      end
    end

I don't know if this is a good approach to use elsif block in that case, is there any other alternatives?

you can put it in a .env file so for each environment you put the suitable url

so when you do ENV[CONFIRMATION_ACCOUNT_URL] you will get the correct url depending on the environment of the running app.

You can create .env file for each enviroment likely .env.production and .env.staging or .env.development . Then put your variable to each .env file. Rails will check current enviroment to get your .env variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM