Ask A Question

Notifications

You’re not receiving notifications from this thread.

Adding Scheduled Blog Posts Discussion

Hello Chris, I am facing the issue while sign in locally (it shows password and email are invalid) even my production site is not giving me this issue, Please help.
Thanks in advance!

Reply

I have resolved this issue by my own, but I do not know why do I had to run rails db:seed command again to populate my database with the predefined seed data that I had already set up in my seed.rb file.

Reply

In the last video we changed the database to PostgreSQL and had to re-create the databases. As a result, this caused us to lose our data on our local machines. Therefore we needed to run rails db:seed again to populate it with the user so that we can login.

Hopefully that explains the issues you were having :D

Reply

Sure, Thanks a lot!

Reply

Hi Chris, one thing wasn´t clear to me. Why do we need those helper methods (draft?, published?, scheduled?), since setting the scopes already give us the ability to get BlogPost.draf and so on?

Reply

The scopes work at the class level, so those will get you a collection of BlogPost records that are all either drafts, published, or scheduled.

The helpers are instance methods, designed to be used with a single blog post instance/record.

The helpers/instance methods are nice because it will not always be the case that you want a collection of draft posts, for example, you may be on the show page for a particular blog post and you could then use the helpers/instance methods to check the published_at status of that particular blog post instance.
Hope that helps!

Reply

Thanks! Great explanation :))

Reply

The CSS for draft posts is working, but for some reason the CSS isn't being applied to scheduled posts.

Works:

Draft

Doesn't work:

Scheduled
Reply

Hi Jonathan, I have the same issue.

It works if you use the same css, but if you change the css, it doesn't work:

works for both:

<% if blog_post.draft? %>
  <div class="p-2 rounded bg-gray-100 text-gray-900">Draft</div>
<% elsif blog_post.scheduled? %>
  <div class="p-2 rounded bg-gray-100 text-gray-900">Scheduled</div>
<% end %>

works only for draft:

<% if blog_post.draft? %>
  <div class="p-2 rounded bg-gray-100 text-gray-900">Draft</div>
<% elsif blog_post.scheduled? %>
  <div class="p-2 rounded bg-blue-100 text-gray-900">Scheduled</div>
<% end %>
Reply

Did anyone find a solution for this? I'm facing the same issue

Reply

Bumping up for March. I have the same issue; nothing I've tried has made the scheduled color work.

Reply

Use the bin/dev command to start your server as noted in video 12 (Adding TailwindCSS to Rails). Otherwise the site does not get all the tailwindcss built in.

Reply

My posts aren't displaying in the correct order. I have the following line in my blog_post.rb:

scope :sorted, -> { order(published_at: :desc, updated_at: :desc) }

And in my controller I have:

def index
@blog_posts = user_signed_in? ? BlogPost.sorted : BlogPost.published.sorted
end

The order seems to be the opposite of what shows in the video.

Reply

Facing the same issue

Reply
Reply

For future viewers, the wrong sorting where drafts can appear on top has been addressed in the following video "Sorting Blog Posts With Scopes". Essentially a postgresql version mismatch can cause this inconsistency. In the follow-up video, Chris explicitly pushes NULLs last, as the deployment surfaces this issue.

Reply

If anyone also has timezone issues with scheduled posts, make sure to set it inside config/application.rb.
You also need to save the post again to reflect that new timezone.

Reply

The helpers are instance methods, designed to be used with a single blog post instance/record.

Reply
Join the discussion
Create an account Log in

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

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

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