>
> NoMethodError in LibrariesController#pictshow
> undefined method `picts' for nil:NilClass
>
`@library``nil``@library.picts``NoMethodError
scaffold
class LibrariesController < ApplicationController
before_action :set_library, only: [:show, :edit, :update, :destroy]
def show
end
private
# Use callbacks to share common setup or constraints between actions.
def set_library
@library = Library.find(params[:id])
end
end
`set_library``@library`idLibrary`set_library`
before_action :set_library, only: [:show, :edit, :update, :destroy]
()`before_action``@library`(`nil`)
@docs = @library.docs.where(params[:library_id])
`@library.docs`
@docs = Doc.where(library_id: @library.id)
@docs = @library.docs
`where(params[:library_id])``where(10)`
(SQL`SELECT ... WHERE TRUE`)