简体   繁体   English

Rails.env 的 Rails elsif 块

[英]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.用于暂存和生产的 URL 在 rails 凭据中,为了避免规范错误,我必须在环境不是暂存或生产时添加new_session_path(resource_name) I've got below elsif block:我有下面的 elsif 块:

    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?我不知道在这种情况下这是否是使用 elsif 块的好方法,还有其他选择吗?

you can put it in a .env file so for each environment you put the suitable url您可以将其放在.env文件中,因此对于每个环境,您都可以放置合适的 url

so when you do ENV[CONFIRMATION_ACCOUNT_URL] you will get the correct url depending on the environment of the running app.因此,当您执行ENV[CONFIRMATION_ACCOUNT_URL]时,您将根据正在运行的应用程序的环境获得正确的 url。

You can create .env file for each enviroment likely .env.production and .env.staging or .env.development .您可以为每个环境创建.env文件,可能是.env.production.env.staging.env.development Then put your variable to each .env file.然后把你的变量放到每个.env文件中。 Rails will check current enviroment to get your .env variable. Rails 将检查当前环境以获取您的.env变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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