d3bug3r
d3bug3r

Reputation: 2586

Heroku rails deployement issues

currently i try to upload my rails app to heroku, but i am having this issues on my 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]: 

I am not very sure about what's going on here, this is my code for routes.rb and 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

Thanks.

Upvotes: 0

Views: 113

Answers (1)

Richard Brown
Richard Brown

Reputation: 11444

The problem seems to be related to your database gem. Heroku uses PostgreSQL (pg) as it's database engine, not sqlite. Make sure you're using pg in production.

See: Undefined method 'accept' for nil:NilClass after upgrading to Rails 3

In my Gemfile I do:

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

group :production do
  gem 'pg'
end

Upvotes: 3

Related Questions