以下是我的状态模型,SatatImage模型和活动管理代码的代码块。在我尝试创建新记录的活动管理员或编辑 - 记录时,我在生产服务器上显示错误。但在开发模式下我的localhost工作, ---------错误---------------------------
app / admin / state.rb:49:在'块(2级)中'
我正在使用Ruby 1.9,Rails 3,2,activeadmin(0.6.0)
======State Model===============
class State < ActiveRecord::Base
attr_accessible :name, :code
validates :code, :uniqueness => true
has_one :state_image, :dependent => :destroy
accepts_nested_attributes_for :state_image, :allow_destroy => true
.......
end
==============StatImage Model=============
class StateImage < ActiveRecord::Base
attr_accessible :state_id, :stateimage, :image_name
belongs_to :state
mount_uploader :stateimage, StateUploader
end
=======Active Admin part=================
ActiveAdmin.register State do
.....
form(html:{multipart:true}) do |f|
f.inputs "State Form" do
f.input :name, required:true
f.input :code, required:true
end
#line-49#
f.inputs "StateImage", for:[:state_image, f.object.state_image || StateImage.new] do |p|
p.input :stateimage, :as => :file, :label => "Image"
end
f.buttons :submit
end
end
答案 0 :(得分:0)
我正在使用
f.semantic_fields_for
并且Formtastic要求您将所有输入包装在&#34;输入&#34;块。所以这应该是:
f.inputs 'State Image' do
f.semantic_fields_for :state_image, (f.object.state_image || StateImage.new) do |p|
p.inputs do
p.input :stateimage, :as => :file, :label => "Image"
p.input :_destroy, :as => :boolean, :required => false, :label => 'Remove image'
end
end
end
答案 1 :(得分:-1)
请试试这个:
form:html =&gt; {:enctype =&gt; “multipart / form-data”} do | f |
同时将activeadmin版本升级到0.6.6