以嵌套形式获取当前对象

sno*_*gel 2 ruby-on-rails nested-forms

一本书has_many夹克,我有一个嵌套的表格来添加它们.我想在右夹克的每组表单字段中都有一个缩略图.在书的编辑视图中获取当前夹克的最佳方法是什么?

books_controller.rb

 def edit
   @book = Book.find(params[:id])
 end
Run Code Online (Sandbox Code Playgroud)

_jacket_fields.html.haml部分

.nested-fields
  = f.inputs do
    = f.input :image, :as => :file, :label => "File name"
  - jacket = # what could go here?
  - if jacket
    = image_tag jacket.image.url(:thumb)
Run Code Online (Sandbox Code Playgroud)

apn*_*ing 10

f.object 是你在找什么.