我在Heroku上的應用程序顯示此錯誤: 很抱歉,但出錯了。 如果您是應用程序所有者,請檢查日誌以獲取更多信息。ActiveRecord :: UnknownAttributeError(未知屬性:user_id):
於是我就Heroku的日誌,並猜到了可能是這個問題:
ActiveRecord::UnknownAttributeError (unknown attribute: user_id):
app/controllers/pins_controller.rb:14:in `new'
我銷控制器
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運行rake db:migrate。謝謝你們。另一個錯誤出現了。
ArgumentError (missing required :bucket option):
app/controllers/pins_controller.rb:22:in `create'
這是綁定到亞馬遜網絡服務?
你在銷表已經user_id說明?如果你這樣做,你是否運行遷移? – Hesham
+1 for'heroku run rake db:migrate' – phoet
原來我還沒有運行heroku run rake db:migrate。現在已經完成了。但遇到了另一個問題(上面加上) –