【发布时间】:2014-02-22 17:07:56
【问题描述】:
我在 Heroku 上的应用显示此错误: 我们很抱歉,但有些不对劲。 如果您是应用程序所有者,请查看日志以获取更多信息。
所以我运行 Heroku 日志并猜测这可能是问题所在:
ActiveRecord::UnknownAttributeError (unknown attribute: user_id):
app/controllers/pins_controller.rb:14:in `new'
我的 Pin 图控制器
class PinsController < ApplicationController
before_action :set_pin, only: [:show, :edit, :update, :destroy]
before_action :correct_user, only: [:edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
def index
@pins = Pin.all
end
def show
end
def new
@pin = current_user.pins.build
end
def edit
end
def create
@pin = current_user.pins.build(pin_params)
if @pin.save
redirect_to @pin, notice: 'Pin was successfully created.'
else
render action: 'new'
end
end
def update
if @pin.update(pin_params)
redirect_to @pin, notice: 'Pin was successfully updated.'
else
render action: 'edit'
end
end
def destroy
@pin.destroy
redirect_to pins_url
end
private
# Use callbacks to share common setup or constraints between actions.
def set_pin
@pin = Pin.find(params[:id])
end
def correct_user
@pin = current_user.pins.find_by(id: params[:id])
redirect_to pins_path, notice: "Not authorized to edit this pin" if @pin.nil?
end
# Never trust parameters from the scary internet, only allow the white list through.
def pin_params
params.require(:pin).permit(:description, :image)
end
end
有什么问题吗?我在寻找正确的调试位置吗?
原来我没有做 heroku run rake db:migrate。谢谢你们。又出现了一个错误。
ArgumentError (missing required :bucket option):
app/controllers/pins_controller.rb:22:in `create'
这是否与 Amazon Web Services 相关联?
【问题讨论】:
-
pins 表中有user_id 吗?如果你这样做了,你是否运行了迁移?
-
为
heroku run rake db:migrate+1 -
原来我还没有运行 heroku run rake db:migrate。现在已经做到了。但是遇到了另一个问题(在上面添加)
-
好的,我设法解决了最后一个错误。 :)。我进入并在 config/environments/production.rb 中将 :bucket => ENV['S3_BUCKET_NAME'], 更改为 :bucket => ENV['AWS_BUCKET']。谢谢大家!
标签: ruby-on-rails activerecord heroku