snowangel
snowangel

Reputation: 3462

Getting the current object in nested forms

A Book has_many jackets, and I've got a nested form to add them. I'd like to have a thumbnail image in each set of form fields of the right jacket. What's the best way to get the current jacket in the book's edit view?

books_controller.rb

 def edit
   @book = Book.find(params[:id])
 end

_jacket_fields.html.haml partial

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

Upvotes: 2

Views: 711

Answers (1)

apneadiving
apneadiving

Reputation: 115511

f.object is what you're looking for.

Upvotes: 10

Related Questions