繁体   English   中英

Heroku Rails部署问题

[英]Heroku rails deployement issues

目前,我尝试将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.rbPostsController代码

routes.rb

Apps2::Application.routes.draw do

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

  resources :posts

  root :to => 'posts#index'
end

后控制器

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

谢谢。

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

参见: 升级到Rails 3后,nil:NilClass的未定义方法'accept'

在我的Gemfile我这样做:

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

group :production do
  gem 'pg'
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM