【问题标题】:rails 4.1 Activeadmin with paperclip, add image button pressed no responserails 4.1 Activeadmin与回形针,添加图像按钮按下无响应
【发布时间】:2014-12-29 10:19:07
【问题描述】:

我想通过回形针将图像上传到活动管理仪表板中的某个位置,但是当我按下“添加新位置图片”时,什么也没发生。图片如下:

model/place.rb

class Place < ActiveRecord::Base

  has_many :place_pictures,     :dependent => :destroy, 
                                :autosave => true
  accepts_nested_attributes_for :place_pictures, 
                                :allow_destroy => true
end

model/place_picture.rb

class PlacePicture < ActiveRecord::Base
  belongs_to :place

  attr_accessible :picture, :logo
  has_attached_file :picture, :styles => { :medium => "300x300>", :thumb => "100x100>" },
                              :default_url => "/images/:style/missing.png"
  validates_attachment_content_type :picture, :content_type => /\Aimage\/.*\Z/
end

admin/place.rb ActiveAdmin.register 地方做

    form :html => { :enctype => "multipart/form-data" } do |f|
      f.inputs "Place details" do
        f.input :name
        f.input :about
        f.has_many :place_pictures do |ff|
          ff.input :picture, :as => :file, :hint => ff.template.image_tag(ff.object.picture.url(:thumb))
          ff.input :logo, as: :boolean, :label => "isLogo"
        end       
      end
     f.actions
    end

   index do
      column :id
      column :name
      column :city
      column :about
      column "Images" do |place|
          if !(place.place_pictures.empty?)
            ul do
               place.place_pictures.each do |img|
                  li do
                    image_tag(img.picture.url(:thumb))
                  end
               end
             end
            end
         end
      actions
     end

    show do |ad|
      attributes_table do
        row :name
        row :city
        row :about
        row :image do
          if !(place.place_pictures.empty?)
            ul do
          place.place_pictures.each do |img|
            li do
            image_tag(img.picture.url(:thumb))
          end
         end
        end
        end
      end
     end
     #active_admin_comments
   end
 end

宝石文件:

gem 'rails'#version 4.1.8
gem 'activeadmin', github: 'activeadmin'
gem "paperclip", "~> 4.2"

它之前在 rails 3.x 和 active_admin 0.6.x 上运行良好。有什么帮助吗?谢谢!

更新: 最后把 active_admin.js 改成下面,就可以了!不知道为什么!希望对遇到这种情况的人有所帮助。

 // = require jquery
 // = require jquery_ujs
 // = require active_admin/base

【问题讨论】:

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


    【解决方案1】:

    似乎附加字段 (has_many) 的 javascript 不起作用。你的系统上有 JavaScript 运行时吗?以 Node.js 为例。

    https://github.com/sstephenson/execjs

    【讨论】:

    • 我不认为这是 JavaScript 运行时问题,但我仍然安装了 Node.js,没有任何帮助。谢谢你的回答。
    猜你喜欢
    • 1970-01-01
    • 2013-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多