I am trying to build nested routes and as mentioned here I m trying to edit my boat picture as <%= link_to "edit", edit_boat_picture_path(@boat, picture) %>. But when I try it, it throws an error undefined local variable or methodpicture' for #<#:0x007f9637811ee0>`
my picture controller is; (probably destroy is wrong also)
class PicturesController < ApplicationController
before_action :logged_in_user
before_filter :load_parent
def index
@picture = @boat.pictures.all
end
def new
@picture = @boat.pictures.new
end
def show
@pictures = @boat.pictures.find(params[:id])
end
def create
@picture = @boat.pictures.new(picture_params)
if @picture.save
#flash[:success] = "Continue from here"
render 'show'
else
render 'new'
end
end
def edit
@picture = Picture.find(params[:id])
end
def update
@picture = @boat.pictures.find(params[:id])
if @picture.update_attributes(picture_params)
flash[:notice] = "Successfully updated picture."
render 'show'
else
render 'edit'
end
end
def destroy
@picture = @boat.pictures.find(params[:id])
@picture.destroy
flash[:notice] = "Successfully destroyed picture."
redirect_to @picture.boat
end
private
def picture_params
params.require(:picture).permit(:name, :image)
end
def load_parent
@boat = Boat.find(params[:boat_id])
end
end