user984621
user984621

Reputation: 48443

Rails: ActionView::Template::Error - undefined method 'comment'

I have a problem with rendering form for input data. The controller looks like this:

class AdsController < ApplicationController
  def new
    @ad = current_user.ads.build()
    respond_to do |format|
      format.html { render :layout => 'new' }# new.html.erb
      format.json { render json: @ad }
    end
  end
end

In the view (the relevant parts):

<%= form_for ([@ad.user, @ad]) do |f| %>
  ...
  <%= f.label 'Description' %></div>
  <%= f.text_area :comment, cols:35, rows:4 %>
  ...
<% end %>

And the model:

class Ad < ActiveRecord::Base
  attr_accessible :title, :url, :comment, :category_id, :layout, :user_id
  ...
end

When I render the form, I get the error:

ActionView::Template::Error (undefined method `comment' for

)

It's weird, because on localhost it's working, but after uploading the app to Heroku I am getting that error.

Where could be a problem?

Upvotes: 0

Views: 2013

Answers (3)

JCB90
JCB90

Reputation: 83

My database migrations were all up to date, so restarting the heroku dyno fixed this problem for me. I ran:

heroku ps:restart

Upvotes: 0

sands19
sands19

Reputation: 101

Restarting the heroku dyno worked for me

$ heroku ps:restart

Upvotes: 1

catsby
catsby

Reputation: 11342

Check your migrations:

$ heroku run rake db:migrate:status

Confirm that you've ran all migrations. Heroku does not automatically run your migrations when you push new code.

Run $ heroku run rake db:migrate to run them.

Upvotes: 1

Related Questions