【发布时间】:2015-04-21 15:16:32
【问题描述】:
我正在尝试构建嵌套路线,如 here 所述,我正在尝试将我的船图片编辑为 <%= link_to "edit", edit_boat_picture_path(@boat, picture) %>。但是当我尝试它时,它会为 #`
undefined local variable or methodpicture'
我的图片控制器是; (可能破坏也是错误的)
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
【问题讨论】:
标签: ruby-on-rails controller routes nested edit