我正在尝试为我的 Gallery 模型编写一个 ActiveAdmin 表单,该表单与我的 Image 模型具有 HABTM 关系。
请注意,这不是这个问题的重复,因为我已经在我的 Gallery 模型中使用了“accepts_nested_attributes_for”。
这是我抛出错误的图库表单:
<% @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 %>
这是我的画廊模型:
class Gallery < ActiveRecord::Base
belongs_to :admin_user
has_and_belongs_to_many :images
accepts_nested_attributes_for :images
end
这是我的图像模型:
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
这是错误日志:
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'