Ask A Question

Notifications

You’re not receiving notifications from this thread.

Scheduling Posts Discussion

Discussion for Scheduling Posts

Great tutorial - thanks! While everything appears to be working fine, I'm still running into the turbolinks caching issues you spoke of at the ~22min mark even after installing the jquery-turbolinks gem (and restarting the server). Is there some additional configuration that needs to happen in order for the gem to prevent that buggy js behavior? Thanks in advance!

Reply

That's a great question Brian. I think that what I was experiencing was that the jQuery code I wrote never gets re-executed when the page changes via Turbolinks. Usually jquery-turbolinks fixes that by hijacking the page change event and that automatically fixes it. You might double check to make sure that jquery-turbolinks is being included in your application.js file properly. That's about the only thing that I can think of off the top of my head.

Reply

I've gone through this, but when trying to load the form. I get `undefined method `published_at?' for nil:NilClass`.

My helper to my eye, looks word for word as per the example: (my model is article, not post)

module ArticlesHelper
def status_for(article)
if article.published_at?
if article.published_at > Time.zone.now
"Scheduled"
else
"Published"
end
else
"Draft"
end
end
end

Reply

To fix the Turbolinks issue you could put your js into a wrapper like this:

$(document).on("turbolinks:load", function() {
  # your javascript goes here...
});

What do you guys think?

Reply

Hi Chris,

Since Rails 6, to the best of my knowledge, no longer supports CoffeeScript, do you have a suggestion for using this with Webpack for those who aren't familiar with Coffee Script?

Reply

CoffeeScript works just fine in Rails 6. https://github.com/rails/webpacker#coffeescript

Reply

Hi Chris,

I followed this video to add draft and scheduled post to Rails 6 a few weeks ago. I ran into one issue with the Publish At dates showing when first going to the Article page. But when the page was refreshed, it worked properly.

I found at that time, if I changed the following in application.js require("turbolinks").start() to require("turbolinks") - it behaved as you would expect.

I've now add AJAX uploading and needed to add some further jQuery. This made me have to re-add the .start() to the turbolinks require.

Any suggestions on how I can have this work properly with Rails 6?

Thanks,

Nav

Reply
Join the discussion
Create an account Log in

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

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

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