Ask A Question

Notifications

You’re not receiving notifications from this thread.

Error with the Scheduled Posts Episode

Simon Cooper asked in General

I've jsut been going through the https://gorails.com/episodes/scheduling-posts episode, but have ran into the issue of undefined method 'published_at?' in my helper, when I try to load the new form page. Did anyone else run into this? My helper is as below, my model is called articles and not posts

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

Hi Simon,

Double check your migration(s) on the Article class/model to make sure you have a published_at column. If it's missing it'll throw a no method error. I cloned the gorails repo for this episode and had no problems with the code Chris wrote.

If you run into any problems, please leave another comment on this thread.

Happy weekend!

Reply

Hey James,

Checked that, and the migration has definately run.

Simons-MBP:gcl Simon$ rails g migration AddPublishedatToArticles published_at:datetime
Running via Spring preloader in process 22081
      invoke  active_record
      create    db/migrate/20180203182358_add_publishedat_to_articles.rb
Simons-MBP:gcl Simon$ rails db:migrate
== 20180203182358 AddPublishedatToArticles: migrating =========================
-- add_column(:articles, :published_at, :datetime)
   -> 0.0175s
== 20180203182358 AddPublishedatToArticles: migrated (0.0176s) ================
Reply

As a test, try this...

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

Thanks James.

Unfortunately no change with the above addition of .present.

Reply
Join the discussion
Create an account Log in

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

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

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