Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 Heroku-nil:NilClass在控制器操作中更改变量时出错_Ruby On Rails 3_Controller_Heroku - Fatal编程技术网

Ruby on rails 3 Heroku-nil:NilClass在控制器操作中更改变量时出错

Ruby on rails 3 Heroku-nil:NilClass在控制器操作中更改变量时出错,ruby-on-rails-3,controller,heroku,Ruby On Rails 3,Controller,Heroku,我最近在heroku上为我的测试应用程序的某些页面实现了一个视图计数器 它是一个简单的计数器,每次访问用户show操作时只添加一个视图。其工作原理如下: class ProductsController < ApplicationController def show @product = Product.find(params[:id]) @product.views += 1 @product.save end .... end

我最近在heroku上为我的测试应用程序的某些页面实现了一个视图计数器

它是一个简单的计数器,每次访问用户show操作时只添加一个视图。其工作原理如下:

 class ProductsController < ApplicationController
  def show
      @product = Product.find(params[:id])
      @product.views += 1
      @product.save
  end 

  ....
 end
现在我已经解决了一些问题,@product变量肯定不是nil。例如,我已将视图/保存行替换为

 redirect_to root_path if @product.nil?
它没有重定向到root_路径,这表明变量实际上不是nil。希罗库为什么要这样做?我能做些什么来修复它?

第一轮。 我确信您忘记运行迁移,因此
.views
不存在

 rake db:migrate

基本上。。该迁移在heroku上不起作用(但当一个服务器回滚并重新迁移时,它会运行)。谢谢。
 rake db:migrate