All threads / Can I assign dates to display a link?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Can I assign dates to display a link?

Nicolás Bobb asked in General

Hello, I'm doing an application where I have to show a link. The administrative must be able to assign the date where it is displayed and hidden. Sorry for my English.
I think it's done with the gem delayed job, right?

Greetings.

As far as I understand situation, you don't need background jobs here. To display something on a web page within certain date interval, you just need to add this condition to your view:

<% if (start_date..end_date).cover? DateTime.now %>
  <%= link_to 'Your link', '#' %>
<% end %>

Identical condition check could be implemented within a helper or presenter to keep view cleaner.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,399+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.