2014-12-02 34 views
1

我已安装activeadmin,并且可以正常工作以查看may app的“评论”部分,从而允许我将各个评论添加到我的业务所在的各个位置。我尝试添加相同的设置,但使用BusinessReviews模型而不是评论(因此允许我在相同基础上添加商业评论)Active Admin中突然没有方法错误?

一切正常,直到我进入活动管理员(登录并访问'Business评论面板是罚款,直到我尝试和实际添加对商家的评论,然后我得到的错误:

NoMethodError in Admin::BusinessReviews#new

undefined method `business_profile_image' for #<BusinessReview:0x007f893fe853d0> 

我的模型如下:

class BusinessReview < ActiveRecord::Base 
belongs_to :location 
    has_many :images, :as => :referrer 
    accepts_nested_attributes_for :images, :allow_destroy => true 
    def thumbnail 
    if self.images.count > 0 
     self.images.last.avatar(:thumb) 
    else 
     nil 
    end 
    end 
end 

my_app应用/管理/ business_review.rb如下:

ActiveAdmin.register BusinessReview do 
    index do 
    column :business_reviewer_name 
    column :business_review_content 
    column :business_reviewer_address 
    column :rating 
    column :location do |business_review| 
     business_review.location.name 
    end 
    column :business_profile_image do |business_review| 
     image_tag(business_review.business_profile_image) if business_review.business_profile_image.present? 
    end 
    actions 
    end 

    show do |business_review| 
    attributes_table do 
     row :business_reviewer_name 
     row :business_profile_image 
     row :business_review_content 
     row :business_reviewer_address 
     row :rating 
     row :location do 
     business_review.location.name 
     end 
    end 
    panel "Images" do 
     table_for business_review.images do 
     column {|img| img.currently_used } 
     column {|img| image_tag(img.avatar.url(:large)) } 
     end 
    end 
    active_admin_comments 
    end 

    permit_params [:id, :business_reviewer_name, :business_profile_image, :business_review_content, :business_reviewer_address, :rating, :location_id], images_attributes: [:id,:_destroy,:avatar,:usage_type, :currently_used] 

    form do |f| 
    f.inputs 'Details' do 
     f.input :business_reviewer_name 
     f.input :business_profile_image 
     f.input :business_review_content 
     f.input :business_reviewer_address 
     f.input :rating 
     f.input :location 
    end 

    f.inputs "images" do 
     f.has_many :images, :allow_destroy => true, :heading => 'Images', :new_record => true do |imgf| 
     imgf.input :currently_used 
     imgf.inputs "Attachment", :multipart => true do 
      imgf.input :avatar, :as => :file, :hint => imgf.object.avatar? \ 
      ? imgf.template.image_tag(imgf.object.avatar.url(:large)) 
      : imgf.template.content_tag(:span, "no image yet") 
     end 
     end 
    end 
    f.actions 
    end 
end 

我的架构的相关部分:

create_table "business_reviews", force: true do |t| 
    t.text  "business_reviewer_content" 
    t.string "business_reviewer_name" 
    t.string "business_reviewer_address" 
    t.float "rating" 
    t.string "profile_image" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    end 

的路线似乎是有好的吗?

batch_action_admin_business_reviews POST  /admin/business_reviews/batch_action(.:format) admin/business_reviews#batch 
_action 
      admin_business_reviews GET  /admin/business_reviews(.:format)     admin/business_reviews#index 
            POST  /admin/business_reviews(.:format)     admin/business_reviews#creat 
e 
      new_admin_business_review GET  /admin/business_reviews/new(.:format)    admin/business_reviews#new 
     edit_admin_business_review GET  /admin/business_reviews/:id/edit(.:format)  admin/business_reviews#edit 
       admin_business_review GET  /admin/business_reviews/:id(.:format)    admin/business_reviews#show 
            PATCH  /admin/business_reviews/:id(.:format)    admin/business_reviews#updat 
e 
            PUT  /admin/business_reviews/:id(.:format)    admin/business_reviews#updat 
e 
            DELETE  /admin/business_reviews/:id(.:format)    admin/business_reviews#destr 
oy 

我只是不(从附加给它的巡航能力不分开business_),把它作为一个评论我完全成立的作品,是相同的。

回答

1

根据您的模式没有business_profile_image只是profile_image:

t.string "profile_image" 

因此,要么重新命名列或使用profile_image代替business_profile_image的。