Ad
Ruby Check If It's October To Display Pink Logo
I'd like to use a different logo for breast cancer awareness month (October)...I'd also like the logo to be tested using params so I can ensure it's working up to snuff before October. Clearly doing something wrong!
Controller:
def breast_cancer_logo_month
if params[:breast_cancer_logo_month] || Time.current.month = 10
return true
end
false
end
view:
<% if breast_cancer_logo_month %>
#breast cancer logo
<% else %>
#standard logo
<% end %>
Ad
Answer
Your breast_cancer_logo_month is wrong. You are using a simple equal when you need two. One equal will try override Time.current.month
value which will raise an error.
Plus if you return true or false in a condition, you can just return the condition. And you can add a ? to the method name too.
def breast_cancer_logo_month?
!!params[:breast_cancer_logo_month] || Time.current.month == 10
end
<% if breast_cancer_logo_month? %>
#breast cancer logo
<% else %>
#standard logo
<% end %>
Ad
source: stackoverflow.com
Related Questions
- → Trigger a click with jQuery using link_to of rails 4
- → Adding html data attribute to simple_forms input
- → How to remove parameters from the root URL if it does I18n
- → passing parameters to rails back end from an ajax call
- → Blocking ?page= in robots.txt
- → react js and rails Updating state on a component with active record relationship
- → Kaminari How to process routes as javascript
- → State not passed into prop
- → Cannot read property 'modalIsOpen' of undefined
- → Objects not valid issue
- → How to map API params to model
- → Consuming webhooks shopify-api
- → How to add ScriptTag on shopify_api gem?
Ad