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!
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.
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
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?
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!
The CSS for draft posts is working, but for some reason the CSS isn't being applied to scheduled posts.
Works:
Doesn't work:
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 %>
Bumping up for March. I have the same issue; nothing I've tried has made the scheduled color work.
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.
This still seems to be an issue :( I even tried setting multiple other colors and only gray seems to work
Addendum: Whilst it does not display locally for me correctly, it does when I connect via Render page ... weird
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.
The final implementation seems different btw https://github.com/gorails-screencasts/learning-path-blog/blob/main/app/models/blog_post.rb#L8
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.
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.
The helpers are instance methods, designed to be used with a single blog post instance/record.
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