1

尝试将代码推送到 Heroku,成功时显示错误:(下面的 Heroku 日志)

2013-05-11T11:37:04.274936+00:00 app[web.1]: Started GET "/" for 27.96.210.68 at 2013-05-11 11:37:04 +0000
2013-05-11T11:37:04.396321+00:00 app[web.1]: Completed 500 Internal Server Error in 1ms
2013-05-11T11:37:04.394455+00:00 app[web.1]: Processing by PinsController#index as HTML
2013-05-11T11:37:04.397564+00:00 app[web.1]: 
2013-05-11T11:37:04.397564+00:00 app[web.1]: 
2013-05-11T11:37:04.397564+00:00 app[web.1]: NameError (uninitialized constant PinsController::Pin):
2013-05-11T11:37:04.397564+00:00 app[web.1]: 
2013-05-11T11:37:04.397564+00:00 app[web.1]:   app/controllers/pins_controller.rb:8:in `index'
2013-05-11T11:37:04.398291+00:00 heroku[router]: at=info method=GET path=/ host=tranquil-brushlands-4435.herokuapp.com fwd="27.96.210.68" dyno=web.1 connect=1ms service=139ms status=500 bytes=643
2013-05-11T11:50:10.989828+00:00 heroku[api]: Starting process with command `rails c` by sgriffiths1975@gmail.com
2013-05-11T11:50:14.120752+00:00 heroku[run.9334]: Awaiting client
2013-05-11T11:50:14.120752+00:00 heroku[run.9334]: Starting process with command `rails c`
2013-05-11T11:50:15.299046+00:00 heroku[run.9334]: State changed from starting to up
2013-05-11T11:51:35.281904+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by sgriffiths1975@gmail.com
2013-05-11T11:51:38.286594+00:00 heroku[run.8367]: Awaiting client
2013-05-11T11:51:38.307997+00:00 heroku[run.8367]: Starting process with command `bundle exec rake db:migrate`
2013-05-11T11:51:39.201325+00:00 heroku[run.8367]: State changed from starting to up
2013-05-11T11:51:45.422656+00:00 heroku[run.8367]: State changed from up to complete
2013-05-11T11:51:45.408277+00:00 heroku[run.8367]: Process exited with status 0

转到 heroku“ http://tranquil-brushlands-4435.herokuapp.com/ ”,它显示“我们很抱歉,但出了点问题。”

看起来是 Pins 控制器详细信息的问题,如下所示:

class PinsController < ApplicationController
  before_filter :authenticate_user!, except: [:index, :show]

  # GET /pins
  # GET /pins.json
  def index
    @pins = Pin.order("created_at desc")

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @pins }
    end
  end

不知道为什么它抱怨这@pins = Pin...条线。在本地工作正常只是无法让它工作Heroku

您好,请找到以下引脚型号的代码:

:class Pin < ActiveRecord::Base
  attr_accessible :description, :image

  validates :description, presence: true
  validates :user_id, presence: true
  validates_attachment :image, presence: true,
                       content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] },
                       size: { less_than: 5.megabytes }
  belongs_to :user
  has_attached_file :image, styles: { medium: "320x240>"}
end

- below is all the pin controller code


class PinsController < ApplicationController
  before_filter :authenticate_user!, except: [:index, :show]

  # GET /pins
  # GET /pins.json
  def index
    @pins = Pin.order("created_at desc")

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @pins }
    end
  end

  # GET /pins/1
  # GET /pins/1.json
  def show
    @pin = Pin.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @pin }
    end
  end

  # GET /pins/new
  # GET /pins/new.json
  def new
    @pin = current_user.pins.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @pin }
    end
  end

  # GET /pins/1/edit
  def edit
    @pin = current_user.pins.find(params[:id])
  end

  # POST /pins
  # POST /pins.json
  def create
    @pin = current_user.pins.new(params[:pin])

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

  # PUT /pins/1
  # PUT /pins/1.json
  def update
    @pin = current_user.pins.find(params[:id])

    respond_to do |format|
      if @pin.update_attributes(params[:pin])
        format.html { redirect_to @pin, notice: 'Pin was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @pin.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /pins/1
  # DELETE /pins/1.json
  def destroy
    @pin = current_user.pins.find(params[:id])
    @pin.destroy

    respond_to do |format|
      format.html { redirect_to pins_url }
      format.json { head :no_content }
    end
  end
end
4

0 回答 0