I'm trying to write an ActiveAdmin form for my Gallery model that has a HABTM relationship with my Image model.
Note that this is not a duplicate of this question, as I am already using "accepts_nested_attributes_for" in my Gallery model.
Here is my Gallery form that throws the error:
<% @gallery.images.build %>
<%= semantic_form_for [:admin, @gallery] do |g| %>
<%= g.inputs "Details" do %>
<%= g.input :title %>
<%= g.input :images, :as => :check_boxes, :label_method => Proc.new { |image| image_tag(image.thumb_path, :alt => "") + content_tag("h3", image.title) } %>
<% end %>
<%= g.inputs :for => :images, :name => "New Image" do |image| %>
<% if image.new_record? %>
<%= image.input :title %>
<%= image.input :asset, :as => :file %>
<% end %>
<% end %>
<%= g.buttons %>
<% end %>
Here is my Gallery model:
class Gallery < ActiveRecord::Base
belongs_to :admin_user
has_and_belongs_to_many :images
accepts_nested_attributes_for :images
end
Here is my Image model:
class Image < ActiveRecord::Base
belongs_to :admin_user
has_and_belongs_to_many :galleries
has_attached_file :asset, :styles => {
:thumb => "96x96#"
}
validates_attachment_presence :asset
end
Here is the error log:
NoMethodError in Admin/galleries#edit
Showing /home/***/www/***/app/views/admin/galleries/_form.html.erb where line #8 raised:
undefined method `new_record?' for #<Formtastic::SemanticFormBuilder:0x164b2088>
Extracted source (around line #8):
5: <%= g.input :images, :as => :check_boxes, :label_method => Proc.new { |image| image_tag(image.thumb_path, :alt => "") + content_tag("h3", image.title) } %>
6: <% end %>
7: <%= g.inputs :for => :images, :name => "New Image" do |image| %>
8: <% if image.new_record? %>
9: <%= image.input :title %>
10: <%= image.input :asset, :as => :file %>
11: <% end %>
Trace of template inclusion: /home/bdastous/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activeadmin-0.3.1/app/views/active_admin/resource/edit.html.arb
Rails.root: /home/bdastous/www/hotel_app_cms
Application Trace | Framework Trace | Full Trace
app/views/admin/galleries/_form.html.erb:8:in `block (2 levels) in _app_views_admin_galleries__form_html_erb__372176781_187575760'
app/views/admin/galleries/_form.html.erb:7:in `block in _app_views_admin_galleries__form_html_erb__372176781_187575760'
app/views/admin/galleries/_form.html.erb:2:in `_app_views_admin_galleries__form_html_erb__372176781_187575760'