我正在尝试在rails_admin中构建拖放图像关联。
我放置了与该地方相关的模型和许多图像。图像将在之前上传并与地点相关联。
我在rails_admin中创建了自定义操作。
rails_admin.rb
# Registering Custom Actions
module RailsAdmin
module Config
module Actions
class ImageAssociate < RailsAdmin::Config::Actions::Base
RailsAdmin::Config::Actions.register(self)
end
end
end
end
# Adding Custome action to RA actions
config.actions do
dashboard
index
new
show
edit
delete
image_associate
end
lib目录中的rails_admin_image_associate.rb
require 'rails_admin/config/actions'
require 'rails_admin/config/actions/base'
module RailsAdminImageAssociate
end
module RailsAdmin
module Config
module Actions
class ImageAssociate < RailsAdmin::Config::Actions::Base
register_instance_option :link_icon do
'icon-picture'
end
# Its Memeber Function
register_instance_option :member do
true
end
register_instance_option :controller do
Proc.new do
@associated_images = @object.images
@images = Image.all - @associated_images
# binding.pry
@image_type = @images.collect(&:asset_type)
# flash[:notice] = "You have approved the review titled: #{@object.name}"
end
end
end
end
end
end
我在rails_admin.rb
中添加了它require Rails.root.join('lib', 'rails_admin_image_associate.rb')
视图/ rails_admin /主/ image_associate.rb
<%= stylesheet_link_tag "rails_admin/image_associate.css" %>
<div id="all_images" class="span4">
<select name="image_type" id="image_type">
<option value="all">all</option>
<% @image_type.each do |type| %>
<option value="<%=type%>"><%=type%></option>
<%end%>
</select>
<% @images.each do |image| %>
<img src="<%=image.file.thumb%>">
<%end%>
</div>
<div id="associated_images" class="span7">
<% @associated_images.each do |aimage| %>
<img src="<%=aimage.file.thumb%>">
<%end%>
</div>
<div class="clearfix">
</div>
现在我需要在选择框“image_type”上触发“更改事件”。我覆盖了rails_admin中的“ui.js”并包含了自定义js文件
资产/ JavaScript的/ rails_admin /定制/ ui.js
//= require_tree .
资产/ JavaScript的/ rails_admin /定制/ image_associate.js
$('#image_type').on('change',function () {
alert("change triggered");
});
我可以看到这个文件是在前端加载的。但事件并未触发。
SCREENSHOT
答案 0 :(得分:3)
尝试:
$(document).on('change', '#image_type',function () {
alert("change triggered");
});