简体   繁体   English

Active Admin中突然没有方法错误?

[英]Sudden no method error in Active Admin?

I have activeadmin installed and working fine for a 'reviews' section of may app, allowing me to add individual reviews to various locations in which my business is based. 我已经安装了activeadmin,并且可以在may应用程序的“评论”部分中正常工作,从而可以将个人评论添加到业务所基于的各个位置。 I tried to add the identical set up but using a BusinessReviews model rather than Reviews (thus allowing me to add business reviews on the same basis) 我尝试添加相同的设置,但是使用的是BusinessReviews模型而不是Reviews(因此,我可以在相同的基础上添加业务评论)

Everything works fine until I go into active admin (log in and accessing the 'Business Reviews' panel is fine, until I try and actually add a business review. I then get the error: 一切正常,直到我进入活动管理员状态(登录并访问“业务评论”面板就可以了,直到我尝试实际添加业务评论为止。然后出现错误:

NoMethodError in Admin::BusinessReviews#new

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

My model is as follows: 我的模型如下:

    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/admin/business_review.rb is as follows: my_app / admin / 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

Relevant part of my schema: 我的架构的相关部分:

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

The routes appear to be there ok too? 路线似乎也可以吗?

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

I just don't get it as the reviews one I set up works perfectly and is identical (apart from the not haveing business_ appended to it). 我只是没有得到它,因为我设置的评论非常完美并且完全相同(除了没有添加business_之外)。

According to your schema there is no business_profile_image but just profile_image: 根据您的架构,没有business_profile_image,只有profile_image:

t.string   "profile_image"

So either rename the column or use profile_image instead of business_profile_image. 因此,要么重命名列,要么使用profile_image而不是business_profile_image。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM