Heroku导致部署问题

时间:2013-03-16 14:27:37

标签: ruby-on-rails ruby ruby-on-rails-3 heroku

目前我尝试将我的rails应用程序上传到heroku,但我在CLI上遇到了这个问题:

2013-03-16T14:21:28+00:00 app[web.1]: Processing by PostsController#index as HTML
2013-03-16T14:21:28+00:00 app[web.1]: Completed 500 Internal Server Error in 1ms
2013-03-16T14:21:28+00:00 app[web.1]: 
2013-03-16T14:21:28+00:00 app[web.1]: NoMethodError (undefined method `accept' for nil:NilClass):
2013-03-16T14:21:28+00:00 app[web.1]:   app/controllers/posts_controller.rb:5:in `index'
2013-03-16T14:21:28+00:00 app[web.1]: 
2013-03-16T14:21:28+00:00 app[web.1]: 

我不太确定这里发生了什么,这是我的routes.rb代码和PostsController

的routes.rb

Apps2::Application.routes.draw do

  devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }

  resources :posts

  root :to => 'posts#index'
end

PostController中

class PostsController < ApplicationController
  # GET /posts
  # GET /posts.json
  def index
    @posts = Post.all

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

  # GET /posts/1
  # GET /posts/1.json
  def show
    @post = Post.find(params[:id])

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

  # GET /posts/new
  # GET /posts/new.json
  def new
    @post = Post.new

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

  # GET /posts/1/edit
  def edit
    @post = Post.find(params[:id])
  end

  # POST /posts
  # POST /posts.json
  def create
    @post = Post.new(params[:post])

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

  # PUT /posts/1
  # PUT /posts/1.json
  def update
    @post = Post.find(params[:id])

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

  # DELETE /posts/1
  # DELETE /posts/1.json
  def destroy
    @post = Post.find(params[:id])
    @post.destroy

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

感谢。

1 个答案:

答案 0 :(得分:3)

问题似乎与您的数据库gem有关。 Heroku使用PostgreSQL(pg)作为它的数据库引擎,而不是sqlite。确保您在生产中使用pg

请参阅:Undefined method 'accept' for nil:NilClass after upgrading to Rails 3

在我的Gemfile我这样做:

group :development, :test do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
end