0

My app on Heroku shows this error: We're sorry, but something went wrong. If you are the application owner check the logs for more information.

So I ran Heroku logs and guessed this could be the problem:

ActiveRecord::UnknownAttributeError (unknown attribute: user_id):
app/controllers/pins_controller.rb:14:in `new'

My Pins controller

class PinsController < ApplicationController
  before_action :set_pin, only: [:show, :edit, :update, :destroy]
  before_action :correct_user, only: [:edit, :update, :destroy]
  before_action :authenticate_user!, except: [:index, :show]



def index
    @pins = Pin.all
  end

  def show
  end

  def new
    @pin = current_user.pins.build
  end

  def edit
  end

  def create
    @pin = current_user.pins.build(pin_params)
    if @pin.save
      redirect_to @pin, notice: 'Pin was successfully created.'
    else
      render action: 'new'
    end
  end



def update
    if @pin.update(pin_params)
      redirect_to @pin, notice: 'Pin was successfully updated.'
    else
      render action: 'edit'
    end
  end

  def destroy
    @pin.destroy
    redirect_to pins_url
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_pin
      @pin = Pin.find(params[:id])
    end

    def correct_user
      @pin = current_user.pins.find_by(id: params[:id])
      redirect_to pins_path, notice: "Not authorized to edit this pin" if @pin.nil? 
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def pin_params
      params.require(:pin).permit(:description, :image)
    end
end

Anything wrong? Am I looking at the right place to debug?

Turns out I didn't do heroku run rake db:migrate. Thanks guys for that. Another error came up.

ArgumentError (missing required :bucket option):
app/controllers/pins_controller.rb:22:in `create'

Is this tied to Amazon Web Services?

3
  • 2
    Do you have user_id in pins table? If you do, did you run the migrations? Commented Feb 22, 2014 at 17:18
  • Turns out I haven't run heroku run rake db:migrate. Have done it now. But ran into another problem (added above) Commented Feb 23, 2014 at 2:42
  • 1
    Ok guys, I managed to resolve the last error. :). I went into and changed :bucket => ENV['S3_BUCKET_NAME'], to :bucket => ENV['AWS_BUCKET'] in config/environments/production.rb. Thanks to all! Commented Feb 23, 2014 at 3:01

2 Answers 2

1

You combined 2 issues into one question. For the first problem with the unknown attribute user_id you need to run:

heroku run rake db:migrate.

For the second problem with your ArgumentError (missing required :bucket option): error you need to set the heroku config to:

heroku config:set S3_BUCKET_NAME=nameOfYourBucket

Sign up to request clarification or add additional context in comments.

Comments

0

I'd go in New action for plain

@pin = Pin.new

You are using your Create action to add the values from relations, so it should work fine

Other then that, use .new in New and .build in Create

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.