Ruby on rails ActiveRecord::UnknownAttributeError(未知属性:用户id):

Ruby on rails ActiveRecord::UnknownAttributeError(未知属性:用户id):,ruby-on-rails,activerecord,heroku,Ruby On Rails,Activerecord,Heroku,Heroku上的我的应用程序显示此错误: 很抱歉,出了点问题。 如果您是应用程序所有者,请查看日志以了解更多信息 所以我运行了Heroku日志,猜测这可能是问题所在: ActiveRecord::UnknownAttributeError (unknown attribute: user_id): app/controllers/pins_controller.rb:14:in `new' 我的PIN控制器 class PinsController < ApplicationContro

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

这与Amazon Web服务有关吗?

我会为plain采取新的行动

@pin = Pin.new
您正在使用Create操作添加关系中的值,因此它应该可以正常工作


除此之外,使用.new in new和.build in Create将两个问题合并为一个问题。对于未知属性user_id的第一个问题,您需要运行:

heroku运行rake db:migrate

对于
参数错误的第二个问题(缺少必需的:bucket选项):
错误您需要将heroku配置设置为:


heroku config:set S3\u BUCKET\u NAME=nameOfYourBucket

您在PIN表中有用户id吗?如果你这样做了,你运行迁移了吗?
heroku-run-rake-db:migrate的+1证明我没有运行heroku-run-rake-db:migrate。我现在已经做了。但是遇到了另一个问题(添加到上面)好的,伙计们,我设法解决了最后一个错误。我进入并在config/environments/production.rb中将:bucket=>ENV['S3_bucket\u NAME']更改为:bucket=>ENV['AWS_bucket']。谢谢大家!
@pin = Pin.new