Azzar
Azzar

Reputation: 51

Rails model: saving works locally but not on Heroku

I have a Rails model for a Recipe. It has an attribute, views, which counts how many times it has been viewed.

In the show action of my controller, I fetch the model object normally:

@recipe = Recipe.find(params[:id])

Then I increase the view count and save:

@recipe.views = @recipe.views + 1
@recipe.save

This works without a hitch locally, but on Heroku, the save apparently doesn't happen. No errors are thrown.

I can run this exact same code in the rails console on Heroku, and then it works.

The only way I can get it to work, is setting

config.cache_classes = false

in environmenst/production.rb

This is obvously not what I want, but I'm stumped about how to go from here.

I'm running Rails 3.2.8, Ruby 1.9.3 on the Cedar stack, using Postgresql 9.1 in both development and on production.

Upvotes: 5

Views: 1249

Answers (2)

Tony Zito
Tony Zito

Reputation: 534

FWIW to future searchers looking for their own solution, Benjamin Tan's answer (in comments) of heroku restart was what worked for me when I had a similar problem.

Upvotes: 6

DreadPirateShawn
DreadPirateShawn

Reputation: 8412

Copying the answer from the edited question body in order to remove this question from the "Unanswered" filter:

UPDATE: Fixed

Turns out I had a file with another older definition of the controller in the app/controllers directory.

~ answer per Azzar

Upvotes: 0

Related Questions