Skip to main content

Error with the Scheduled Posts Episode

General • Asked by Simon Cooper

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

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!


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) ================

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

Thanks James.

Unfortunately no change with the above addition of .present.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.