0

每次我今天尝试部署时,我都会在 heroku 日志中不断收到这些错误。该应用程序昨晚运行良好,我不确定从那以后发生了什么变化,因为我没有做任何新的事情。

song_controller.rb

class SongsController < ApplicationController
  before_filter :authenticate_user!, only: [:create ,:edit, :update, :destroy, :vote_for_song]
  before_action :set_song, only: [:show, :edit, :update, :destroy, :vote_for_song]

  def extract_video

  @song = Song.find(params[:id])
  @song.YouTubeAddy.extract_video_id

  end

  def vote_for
      @song = Song.find(params[:id])
      current_user.vote_for(@song)
      @song.plusminus = @song.votes_for
      @song.save
      respond_to do |format|
        format.js { render 'update_votes' }
      end
  end

  def vote_against
    @song = Song.find(params[:id])
    current_user.vote_against(@song)
    respond_to do |format|
      format.js { render 'update_votes' }
    end
  end

  def new_songs
    @songs = Song.order("id DESC").paginate(:page => params[:page], :per_page => 15)
    get_last_song
  end


  # GET /Songs
  # GET /Songs.json
  def index
      if params[:query].present? 
      @songs = Song.search(params)
      get_last_song
    elsif params[:genre]
      @songs = Song.tagged_with(params[:genre]).paginate(:page => params[:page], :per_page => 15)
      get_last_song
    else      
      @songs = Song.order('id').order('plusminus desc nulls last').paginate(:page => params[:page], :per_page => 15) 
      #@songs = Song.tally.paginate(:page => params[:page], :per_page => 15)
      get_last_song
    end
  end

  def get_last_song
    if params[:page].nil?
      @last_song = 0
    else
      @last_song = 15 * (params[:page].to_i - 1)
    end
  end

  # GET /Songs/1
  # GET /Songs/1.json
  def show
   @comment = Comment.new(song: @song) 
   @video_tag = YouTubeAddy.extract_video_id(@song.url)

  end

  # GET /Songs/new
  def new
    @song = Song.new
  end

  # GET /Songs/1/edit
  def edit
  end

  # POST /Songs
  # POST /Songs.json
  def create
    @song = Song.new(song_params)

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

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

  # Song /Songs/1
  # Song /Songs/1.json
  def destroy
    @song.destroy
    respond_to do |format|
      format.html { redirect_to songs_url }
      format.json { head :no_content }
    end
  end

  private

    def set_song
       @song = Song.find(params[:id])
     end

     def song_params
       params.require(:song).permit(:title, :artist, :url, :track, :user_id, :tag_list, :query, :genre, :page)
     end
  end

歌曲.rb

class Song < ActiveRecord::Base

  acts_as_voteable

  index_name BONSAI_INDEX_NAME

  belongs_to :user
  has_many :comments, :dependent => :destroy
  has_many :genre_songs
  has_many :genres, through: :genre_songs

  has_attached_file :track
                #  :url  => "/assets/songs/:id/:style/:basename.:extension",
                # :path => ":rails_root/public/assets/songs/:id/:style/:basename.:extension"

  # validates_attachment :track, :presence => true

  validates_presence_of :url

  validates :title, length: { minimum: 10 }
  validates :url, length: { maximum: 300 }
  validates :url, :format => URI::regexp(%w(http https))  

  include Tire::Model::Search
  include Tire::Model::Callbacks

  def self.search(params)
    tire.search(load: true, page: params[:page], per_page: 15) do
      query { string params[:query], default_operator: "AND" } if params[:query].present?

    end
  end

  def to_indexed_json
    to_json(methods: [:genre_names])
  end

  def genre_names
    genres.map{ |g| g.name}   
  end

  def self.tagged_with(name)
    Genre.find_by_name!(name).songs
  end

  def tag_list
    genres.map(&:name).join(", ")
  end

  def tag_list=(names)
    self.genres = names.split(",").map do |n|
      Genre.where(name: n.strip).first_or_create!
    end
  end
end

Heroku错误:

    2013-08-07T19:15:49.605667+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
    2013-08-07T19:15:49.605667+00:00 app[web.1]: F, [2013-08-07T19:15:49.604633 #2] FATAL -- : 
    2013-08-07T19:15:49.605667+00:00 app[web.1]:   app/controllers/songs_controller.rb:83:in `block in create'
    2013-08-07T19:15:49.605667+00:00 app[web.1]: 
    2013-08-07T19:15:49.605667+00:00 app[web.1]:   app/controllers/songs_controller.rb:82:in `create'
    2013-08-07T19:15:49.605667+00:00 app[web.1]: 
    2013-08-07T19:15:49.620779+00:00 heroku[router]: at=info method=POST path=/songs host=www.leapfm.com fwd="99.233.170.104" dyno=web.1 connect=7ms service=110ms status=500 bytes=1266
 7 19:17:41 +0000
    2013-08-07T19:17:41.781821+00:00 app[web.1]: F, [2013-08-07T19:17:41.781602 #2] FATAL -- : 
    2013-08-07T19:17:41.781821+00:00 app[web.1]: 
    2013-08-07T19:17:41.781821+00:00 app[web.1]: 
    2013-08-07T19:17:41.781821+00:00 app[web.1]: F, [2013-08-07T19:17:41.781666 #2] FATAL -- : 
    2013-08-07T19:17:41.768371+00:00 app[web.1]: I, [2013-08-07T19:17:41.768179 #2]  INFO -- : Started GET "/songs/24" for 72.5.89.102 at 2013-08-07 19:17:41 +0000
    2013-08-07T19:17:41.781821+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find Song with id=24):
    2013-08-07T19:17:41.781821+00:00 app[web.1]:   app/controllers/songs_controller.rb:120:in `set_song'
    2013-08-07T19:17:41.781821+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find Song with id=24):
    2013-08-07T19:17:41.781821+00:00 app[web.1]:   app/controllers/songs_controller.rb:120:in `set_song'
    2013-08-07T19:17:41.781821+00:00 app[web.1]: 
    2013-08-07T19:17:41.781821+00:00 app[web.1]: 
07T19:17:51.527635+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find Song with id=22):
    2013-08-07T19:17:51.527635+00:00 app[web.1]: 
    2013-08-07T19:17:51.527635+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find Song with id=22):

    2013-08-07T19:17:51.527635+00:00 app[web.1]:   app/controllers/songs_controller.rb:120:in `set_song'
    2013-08-07T19:17:51.527635+00:00 app[web.1]:   app/controllers/songs_controller.rb:120:in `set_song'

    2013-08-07T19:21:16.681196+00:00 app[web.1]:   app/models/song.rb:28:in `search'
    2013-08-07T19:21:16.670635+00:00 app[web.1]: I, [2013-08-07T19:21:16.670450 #2]  INFO -- : Started GET "/songs?utf8=%E2%9C%93&query=rap" for 99.233.170.104 at 2013-08-07 19:21:16 +0000
    2013-08-07T19:21:16.681196+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
    2013-08-07T19:21:16.681196+00:00 app[web.1]: F, [2013-08-07T19:21:16.680957 #2] FATAL -- : 
    2013-08-07T19:21:16.681196+00:00 app[web.1]:   app/controllers/songs_controller.rb:40:in `index'
    2013-08-07T19:21:16.681196+00:00 app[web.1]:   app/models/song.rb:28:in `search'
    2013-08-07T19:21:16.681196+00:00 app[web.1]: 
    2013-08-07T19:21:16.681196+00:00 app[web.1]: F, [2013-08-07T19:21:16.681232 #2] FATAL -- : 
    2013-08-07T19:21:16.670635+00:00 app[web.1]: I, [2013-08-07T19:21:16.670529 #2]  INFO -- : Started GET "/songs?utf8=%E2%9C%93&query=rap" for 99.233.170.104 at 2013-08-07 19:21:16 +0000
    2013-08-07T19:21:16.681196+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
    2013-08-07T19:21:16.681558+00:00 app[web.1]: 
    2013-08-07T19:21:16.681196+00:00 app[web.1]: 
    2013-08-07T19:21:16.681196+00:00 app[web.1]:   app/controllers/songs_controller.rb:40:in `index'
    2013-08-07T19:21:16.681558+00:00 app[web.1]: 
    2013-08-07T19:21:16.682976+00:00 heroku[router]: at=info method=GET path=/songs?
    2013-08-07T19:21:32.687381+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
    2013-08-07T19:21:32.687381+00:00 app[web.1]:   app/controllers/songs_controller.rb:83:in `block in create'
    2013-08-07T19:21:32.687381+00:00 app[web.1]:   app/controllers/songs_controller.rb:82:in `create'
    2013-08-07T19:21:32.687381+00:00 app[web.1]: F, [2013-08-07T19:21:32.687331 #2] FATAL -- : 
    2013-08-07T19:21:32.694312+00:00 heroku[router]: at=info method=POST path=/songs host=www.leapfm.com fwd="99.233.170.104" dyno=web.1 connect=3ms service=35ms status=500 bytes=1266
    2013-08-07T19:21:32.687381+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
    2013-08-07T19:21:32.687381+00:00 app[web.1]:   app/controllers/songs_controller.rb:82:in `create'
    2013-08-07T19:21:32.687381+00:00 app[web.1]: 
    2013-08-07T19:21:32.687594+00:00 app[web.1]: 
    2013-08-07T19:21:32.687594+00:00 app[web.1]: 
    2013-08-07T19:21:32.687381+00:00 app[web.1]:   app/controllers/songs_controller.rb:83:in `block in create'

盆景.rb

if ENV['BONSAI_INDEX_URL']
  Tire.configure do
    url "http://kpphwqlo:tsbest4n4cpwd2ou@holly-7515324.us-east-1.bonsai.io"
  end
  BONSAI_INDEX_NAME = ENV['BONSAI_URL'][/[^\/]+$/]
else
  app_name = Rails.application.class.parent_name.underscore.dasherize
  BONSAI_INDEX_NAME = "#{app_name}-#{Rails.env}"
end
4

1 回答 1

1

检查你在heroku上是否有这个变量。

if ENV['BONSAI_INDEX_URL']

这将检查此变量是否存在,如果不存在则设置:

BONSAI_INDEX_NAME = "#{app_name}-#{Rails.env}"

这会给你一个错误的弹性搜索连接。

于 2013-08-07T21:21:35.207 回答