0
votes

I'm getting this error in my pins_controller from the one month course and have no idea how to solve it. Here's my controller.


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

def index
  @pins = Pin.to_a
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

1

1 Answers

2
votes

You should have

Pin.all

instead of

Pin.to_a

in your controller.