mercredi 26 juin 2019

Ruby on Rails if/else condition not working

I have a Rails application view where I want to display one of two partials depending on the ENV variable setting. For some reason, the condition is always evaluated to false so the campaign_active partial is displayed. I've changed the ENV to true and tried switching the rendering statements around and found that only the statement after else gets executed. What am I missing?

Here's the view:

<% if Rails.application.config.ended %>
  <%= render "users/campaign_ended" %>
<% else %>
  <%= render "users/campaign_active" %>
<% end %>

Here's the application.rb setting:

config.ended = ENV['CAMPAIGN_ENDED'].to_s == 'true'

Here's the .ENV file:

CAMPAIGN_ENDED=true

The campaign setting in ENV is set to true so I expect the condition in my view to be true and render the campaign_ended partial. But instead, it renders the campaign_active partial. Now if I switch the statements around and put campaign active ahead of campaign ended, then the campaign ended partial renders.

Aucun commentaire:

Enregistrer un commentaire