Artificial intelligent assistant

Railsで複数のhas_manyを持ったモデルを作りたい librarylibrarydocpict( pict library.rb has_many :docs has_many :picts doc.rb belongs_to :library pict.rb belongs_to :library library def show @docs = @library.docs.where(params[:library_id]) end def pictshow# @picts = @library.picts.where(params[:library_id]) end showpictshow NoMethodError in LibrariesController#pictshow undefined method `picts' for nil:NilClass

>
> 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`)

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 0d811a3b50125fb9248c18b8010a6ee7