Reputation: 2805
I have been using rails for about a month, mostly loving it, sometimes infuriating (I haven't yet gotten particularly efficient at debugging through the magic).
I have a gallery page that extends from a something called simply page. Each gallery page has many gallery images.
class Gallery < Page
belongs_to :page, :dependent => :destroy
has_many :gallery_images, :dependent => :destroy
accepts_nested_attributes_for :gallery_images
end
class GalleryImage < ActiveRecord::Base
has_attached_file :image, :styles => { :medium => "600x600>", :thumb => "100x100>" }
belongs_to :gallery
end
I am trying to edit the gallery through the pages controller.
def edit
@page = Gallery.find(params[:id])
@house = @page.house
end
Through the page/edit.html.erb i render the gallery form partial
<%= form_for @page do |f| %>
<p><b>Images</b></p>
<% for image in @page.gallery_images %>
<%= image.image.url(:thumb) %>
<% end %>
<%= f.fields_for :gallery_images do |builder| %>
<% render :partial => "galleries/gallery_image_fields", :f => builder %>
<% end %>
<p><%= f.submit %></p>
<% end %>
In galleries/gallery_image_fields i have
<p class="fields">
<%= f.label :image %><br />
<%= f.file_field :image %>
</p>
Now the urls for the above image print out so it seems that the relashionship is working fine, however I get the enormously frustrating error message.
undefined local variable or method `f' for #<#:0x210eb34> Showing mypathblahblah/app/views/galleries/_gallery_image_fields.html.erb where line #2 raised:
If anyone has a solution that would obviously be perfect otherwise some thoughts into how one might debug this problem would be great too. I tried outputting debug builder but it didnt really help me.
Thanks
Upvotes: 1
Views: 7899
Reputation: 2483
Try changing:
<% render :partial => "galleries/gallery_image_fields", :f => builder %>
into:
<% render :partial => "galleries/gallery_image_fields", :locals => { :f => builder } %>
Upvotes: 12