活动管理员图像字段显示为脏

时间:2016-07-15 18:13:13

标签: ruby-on-rails ruby-on-rails-4 activeadmin

我在ROR应用程序中使用ActiveAdmin gem作为管理控制台。在我的ActiveAdmin模型 - FeaturedEvent中,我已声明用于创建精选事件的表单。 FeaturedEvent模型作为图像字段,所以我尝试写它。但它在Admin :: FeaturedEvents中表示NoMethodError #new undefined方法`new'为零:NilClass。以下是我的ActiveAdmin模型:

ActiveAdmin.register FeaturedEvent do
permit_params do
permitted = [:name, :location, :start_time, :description,:image,:phone, :email, :event_url, :active, :free, :image, :s3_credentials]
permitted << :other if params[:action] == 'create'
permitted
end

controller do
def create 
    byebug
    @featuredevent = Event.new(permitted_params[:featuredevent])

    if @featuredevent.save
        redirect_to '/admin/featured_events#index'
    else
        flash[:message] = 'Error in creating image.'
    end


end

def event_params
    params.require(:event).permit(:name, :location, :start_time, :description,:image,:phone, :email, :event_url, :active, :free, :image, :s3_credentials)
end
end

form do |f|
inputs 'Create Private Events' do

  input :image
end

actions do
    button_to  'Create', featured_speakers_path(:featuredevent), method: :post
            #link_to 'Create', {:controller => 'events', :action => 'create'}, {:method => :post }
end 
end

end

导航以创建特色事件时浏览器出错:

**NoMethodError in Admin::FeaturedEvents#new**
undefined method `dirty?' for nil:NilClass

1 个答案:

答案 0 :(得分:0)

好的,我明白了。 Paperclip在FeaturedEvent模型中需要一个不同的附件声明名称[我有其他使用图像的模型]。谢谢Vishal