1. Ruby on Rails - Heroku NoMethodError (undefined method `some_column` for … )

    Heroku was acting up on a problem that I didn’t encounter on a developing environment. Apparently, when you create an attribute on a model, it does not come with internally usable setter for that attribute. Here is the explanation for problem I had.

    I have a model called Topic. A Topic has a column called last_post_id. In topics_controller, I had to use setter method for last_post_id to assign it a value. See the line @topic.last_post_id = Post.count + 1

    def create
      @forum = Forum.find(params[:forum_id])
      @topic = @forum.topics.build(params[:topic])
      @topic.last_post_id = Post.count + 1
      if @topic.save
        flash[:success] = "Success!"
        redirect_to topic_posts_path(@topic)
      else
        render 'new'
      end
    end
    

    I thought that a setter and an accessor should be automatically available once you create an attribute of a model, but on Heroku, this doesn’t work.

    So I had to make accessor and setter for last_post_id available in Topic model.

    class Topic < ActiveRecord::Base
      ...
      attr_accessible :last_post_id
      ...
    end