Ruby on rails Rails 4:用户登录后无法上载列表

Ruby on rails Rails 4:用户登录后无法上载列表,ruby-on-rails,heroku,Ruby On Rails,Heroku,我有一个允许用户登录然后创建列表的应用程序。这在localhost上有效,但在我登录并提交列表后在Heroku上会崩溃 NoMethodError(对于#未定义的方法'user_id='): 完全错误如下 Parameters: {"utf8"=>"✓", "authenticity_token"=>"B+y5VOvBRe+TgTEXP+2mbElYy2LqPShkeqxy+pXizHI=", "listing"=>{"name"=>"apples", "descript

我有一个允许用户登录然后创建列表的应用程序。这在localhost上有效,但在我登录并提交列表后在Heroku上会崩溃

NoMethodError(对于#未定义的方法'user_id='):

完全错误如下

Parameters: {"utf8"=>"✓", "authenticity_token"=>"B+y5VOvBRe+TgTEXP+2mbElYy2LqPShkeqxy+pXizHI=", "listing"=>{"name"=>"apples", "description"=>"bunch of apples", "price"=>"2.33", "quantity"=>"12", "company"=>"test", "image"=>#<ActionDispatch::Http::UploadedFile:0x007f3159693278 @tempfile=#<Tempfile:/tmp/RackMultipart20140722-2-7zodjh>, @original_filename="apples.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"listing[image]\"; filename=\"apples.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"Create Listing"}
2014-07-22T16:23:35.323773+00:00 app[web.1]: Command :: file -b --mime '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-4vgehy.jpg'
2014-07-22T16:23:35.323967+00:00 app[web.1]: Command :: file -b --mime '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-4vgehy.jpg'
2014-07-22T16:23:35.595147+00:00 app[web.1]: Command :: identify -format %m '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]'
2014-07-22T16:23:35.775282+00:00 app[web.1]: Command :: convert '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]' -auto-orient -resize "50" '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-8o0hbb'
2014-07-22T16:23:35.595158+00:00 app[web.1]: Command :: identify -format %m '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]'
2014-07-22T16:23:35.775255+00:00 app[web.1]: Command :: convert '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]' -auto-orient -resize "50" '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-8o0hbb'
2014-07-22T16:23:36.165057+00:00 app[web.1]: Command :: file -b --mime '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-8o0hbb'
2014-07-22T16:23:36.165138+00:00 app[web.1]: Command :: file -b --mime '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-8o0hbb'
2014-07-22T16:23:36.258293+00:00 app[web.1]: Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]' 2>/dev/null
2014-07-22T16:23:36.258523+00:00 app[web.1]: Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]' 2>/dev/null
2014-07-22T16:23:36.424127+00:00 app[web.1]: Command :: identify -format %m '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]'
2014-07-22T16:23:36.424101+00:00 app[web.1]: Command :: identify -format %m '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]'
2014-07-22T16:23:36.588678+00:00 app[web.1]: Command :: convert '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]' -auto-orient -resize "100x100>" '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-jb4tv3'
2014-07-22T16:23:36.777832+00:00 app[web.1]: Command :: file -b --mime '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-jb4tv3'
2014-07-22T16:23:36.777843+00:00 app[web.1]: Command :: file -b --mime '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-jb4tv3'
2014-07-22T16:23:36.588555+00:00 app[web.1]: Command :: convert '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu6.jpg[0]' -auto-orient -resize "100x100>" '/tmp/daeccf0ad3c1fc8c8015205c332f5b4220140722-2-mesu620140722-2-jb4tv3'
2014-07-22T16:23:36.863756+00:00 heroku[router]: at=info method=POST path="/listings" host=sincurudemo.herokuapp.com request_id=17e210ab-2955-418b-9dd8-0475a29b3271 fwd="185.30.24.132" dyno=web.1 connect=0 service=1830 status=500 bytes=28895
2014-07-22T16:23:36.856835+00:00 app[web.1]: Completed 500 Internal Server Error in 1618ms
2014-07-22T16:23:36.856688+00:00 app[web.1]: Completed 500 Internal Server Error in 1618ms
2014-07-22T16:23:36.861125+00:00 app[web.1]: 
2014-07-22T16:23:36.861129+00:00 app[web.1]: NoMethodError (undefined method `user_id=' for #<Listing:0x007f3159698f20>):
2014-07-22T16:23:36.861322+00:00 app[web.1]:   app/controllers/listings_controller.rb:36:in `create'
2014-07-22T16:23:36.861141+00:00 app[web.1]:   app/controllers/listings_controller.rb:36:in `create'
2014-07-22T16:23:36.861142+00:00 app[web.1]: 
2014-07-22T16:23:36.861144+00:00 app[web.1]: 
2014-07-22T16:23:36.861317+00:00 app[web.1]: 
2014-07-22T16:23:36.861320+00:00 app[web.1]: NoMethodError (undefined method `user_id=' for #<Listing:0x007f3159698f20>):
2014-07-22T16:23:36.861325+00:00 app[web.1]: 
2014-07-22T16:23:36.861324+00:00 app[web.1]: 
参数:{“utf8”=>“✓", "真实性令牌“=>”B+y5VOvBRe+TgTEXP+2mbElYy2LqPShkeqxy+pXizHI=“,”列表“=>”{“名称”=>“苹果”,“描述”=>“一堆苹果”,“价格”=>“2.33”,“数量”=>“12”,“公司”=>“测试”,“图像”=>,“提交”=>“创建列表”}
2014-07-22T16:23:35.323773+00:00应用程序[web.1]:命令::file-b--mime'/tmp/daecf0ad3c1fc8c8015205c332f5b4240722-2-4vgehy.jpg'
2014-07-22T16:23:35.323967+00:00应用程序[web.1]:命令::file-b--mime'/tmp/daecf0ad3c1fc8c8015205c332f5b4240722-2-4vgehy.jpg'
2014-07-22T16:23:35.595147+00:00应用程序[web.1]:命令::标识-格式%m'/tmp/daecf0ad3c1fc8c8015205c332f5b420140722-2-mesu6.jpg[0]'
2014-07-22T16:23:35.775282+00:00应用程序[web.1]:命令::convert'/tmp/daecf0ad3c1fc8c8015205c332f5b420140722-2-mesu6.jpg[0]'-自动定向-调整“50”大小/tmp/daecf0ad3c1fc8c8015205c32f5b420722-2-mesu6200722-8o0hbb'
2014-07-22T16:23:35.595158+00:00应用程序[web.1]:命令::标识-格式%m'/tmp/daecf0ad3c1fc8c8015205c332f5b420140722-2-mesu6.jpg[0]'
2014-07-22T16:23:35.775255+00:00应用程序[web.1]:命令::convert'/tmp/daecf0ad3c1fc8c8015205c332f5b420140722-2-mesu6.jpg[0]'-自动定向-调整“50”大小/tmp/daecf0ad3c1fc8c8015205c32f5b420722-2-mesu6200722-8o0hbb'
2014-07-22T16:23:36.165057+00:00应用程序[web.1]:命令::文件-b--mime'/tmp/DAECF0AD3C1FC8C8015205C332F5B420140722-2-mesu620140722-2-8o0hbb'
2014-07-22T16:23:36.165138+00:00应用程序[web.1]:命令::文件-b--mime'/tmp/DAECF0AD3C1FC8C8015205C332F5B420140722-2-mesu620140722-2-8o0hbb'
2014-07-22T16:23:36.258293+00:00应用程序[web.1]:命令::标识-格式“%wx%h,%[exif:orientation]”/tmp/daecf0ad3c1fc8c8015205c332f5b420140722-2-mesu6.jpg[0]'2>/dev/null
2014-07-22T16:23:36.258523+00:00应用程序[web.1]:命令::标识-格式“%wx%h,%[exif:orientation]”/tmp/daecf0ad3c1fc8c8015205c332f5b420140722-2-mesu6.jpg[0]'2>/dev/null
2014-07-22T16:23:36.424127+00:00应用程序[web.1]:命令::标识-格式%m'/tmp/daecf0ad3c1fc8c8015205c332f5b420140722-2-mesu6.jpg[0]'
2014-07-22T16:23:36.424101+00:00应用程序[web.1]:命令::标识-格式%m'/tmp/daecf0ad3c1fc8c8015205c332f5b420140722-2-mesu6.jpg[0]'
2014-07-22T16:23:36.588678+00:00应用程序[web.1]:命令::convert'/tmp/daecf0ad3c1fc8c8015205c332f532f5b420140722-2-mesu6.jpg[0]'-自动定向-调整大小“100x100>”/tmp/daecf0ad3c1fc8c8015205c332f5b420722-2-mesu6200722-jb4tv3'
2014-07-22T16:23:36.777832+00:00应用程序[web.1]:命令::文件-b--mime'/tmp/DAECF0AD3C1FC8C8015205C332F5B420140722-2-mesu620140722-2-jb4tv3'
2014-07-22T16:23:36.777843+00:00应用程序[web.1]:命令::文件-b--mime'/tmp/DAECF0AD3C1FC8C8015205C332F5B420140722-2-mesu620140722-2-jb4tv3'
2014-07-22T16:23:36.588555+00:00应用程序[web.1]:命令::convert'/tmp/daecf0ad3c1fc8c8015205c332f5b420140722-2-mesu6.jpg[0]'-自动定向-调整大小“100x100>”/tmp/daecf0ad3c1fc8c8015205c32f5b420722-2-mesu6200722-jb4tv3'
2014-07-22T16:23:36.863756+00:00 heroku[路由器]:at=info method=POST path=“/listings”host=sincurudemo.herokuapp.com请求_id=17e210ab-2955-418b-9dd8-0475a29b3271 fwd=“185.30.24.132”dyno=web.1 connect=0服务=1830状态=500字节=28895
2014-07-22T16:23:36.856835+00:00应用程序[web.1]:在1618毫秒内完成500个内部服务器错误
2014-07-22T16:23:36.856688+00:00应用程序[web.1]:在1618毫秒内完成500个内部服务器错误
2014-07-22T16:23:36.861125+00:00应用程序[网站1]:
2014-07-22T16:23:36.861129+00:00应用程序[web.1]:NoMethodError(未定义的方法'user_id='表示#):
2014-07-22T16:23:36.861322+00:00应用程序[web.1]:应用程序/控制器/列表\u控制器.rb:36:在“创建”中
2014-07-22T16:23:36.861141+00:00应用程序[web.1]:应用程序/控制器/列表\u控制器.rb:36:在“创建”中
2014-07-22T16:23:36.861142+00:00应用程序[网站1]:
2014-07-22T16:23:36.861144+00:00应用程序[网站1]:
2014-07-22T16:23:36.861317+00:00应用程序[网站1]:
2014-07-22T16:23:36.861320+00:00应用程序[web.1]:NoMethodError(未定义的方法'user_id='表示#):
2014-07-22T16:23:36.861325+00:00应用程序[网站1]:
2014-07-22T16:23:36.861324+00:00应用程序[网站1]:
listing.controller.rb

class ListingsController < ApplicationController
  before_action :set_listing, only: [:show, :edit, :update, :destroy]
  before_action :authenticate_user!, only: [:seller, :new, :create, :edit, :update, :destroy]
  before_filter :check_user, only: [:edit, :update, :destroy]

  # GET /listings
  # GET /listings.json

  def seller 
    @listings = Listing.where(user: current_user).order("created_at DESC")
  end


  def index
    @listings = Listing.all.order("created_at DESC")
  end

  # GET /listings/1
  # GET /listings/1.json
  def show
  end

  # GET /listings/new
  def new
    @listing = Listing.new
  end

  # GET /listings/1/edit
  def edit
  end

  # POST /listings
  # POST /listings.json
  def create
    @listing = Listing.new(listing_params)
    @listing.user_id = current_user.id

    respond_to do |format|
      if @listing.save
        format.html { redirect_to @listing, notice: 'Listing was successfully created.' }
        format.json { render action: 'show', status: :created, location: @listing }
      else
        format.html { render action: 'new' }
        format.json { render json: @listing.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /listings/1
  # PATCH/PUT /listings/1.json
  def update
    respond_to do |format|
      if @listing.update(listing_params)
        format.html { redirect_to @listing, notice: 'Listing was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @listing.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /listings/1
  # DELETE /listings/1.json
  def destroy
    @listing.destroy
    respond_to do |format|
      format.html { redirect_to listings_url }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_listing
      @listing = Listing.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def listing_params
      params.require(:listing).permit(:name, :description, :price, :quantity, :company, :image)
    end

    def check_user
      if current_user != @listing.user
        redirect_to root_url, alert: 'Sorry, This listing belongs to someone else'
      end
    end
end
class ListingsControllerclass Listing < ActiveRecord::Base
  if Rails.env.development?
    has_attached_file :image, :styles => { :small => "50x", :thumb => "100x100>" }, :default_url => "default.jpg"
    validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png)

  else
    has_attached_file :image, :styles => { :small => "50x", :thumb => "100x100>" }, :default_url => "default.jpg",
        :storage => :dropbox,
        :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
        :path => ":style/:id_:filename"
  end
  validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png)
  validates_attachment_presence :image


  validates :name, :description, :price, presence: true
  validates :price, numericality: { greater_than: 0 }

  belongs_to :user
end


class AddUserIdToListings < ActiveRecord::Migration
  def change
    add_column :listings, :user_id, :integer
  end
end
def listing_params
  params.require(:listing).permit(:name, :description, :price, :quantity, :company, :image,:user_id)
end