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

This still seems to be an issue :( I even tried setting multiple other colors and only gray seems to work

Reply

Addendum: Whilst it does not display locally for me correctly, it does when I connect via Render page ... weird

Reply

bin/dev fails for me, for some reason, even that show in terminal that "css build..."etc, for me what that help was explicitly build css with:
rake tailwindcss:build

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

You probably increase your subscibers if you have a team that is soley dedicated to problems that arise out of your lessons.. I came here in 2021 and soon realised that errors arise but the time you get back to the problems are years.. and here i am again in 2024 trying again with the same amount of problems.. so why pay? youtube and chat gpt are better options I guess

Reply
Join the discussion
Create an account Log in

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

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

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