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
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
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.
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
Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.