我有以下型号:
Post.rb
class Post < ActiveRecord::Base
belongs_to :category
has_many :attachments, :dependent => :destroy
has_many :citations, :dependent => :destroy
validates :title, :category_id, :content, :presence =>true
acts_as_taggable_on :keywords
accepts_nested_attributes_for :attachments, :allow_destroy => true,
:reject_if => proc { |attributes| attributes['photo'].blank?}
accepts_nested_attributes_for :citations, :allow_destroy=>true
end
Run Code Online (Sandbox Code Playgroud)
Attachment.rb
class Attachment < ActiveRecord::Base
belongs_to :post
has_attached_file :photo, :styles => { :medium => "637x471>",
:thumb => Proc.new { |instance| instance.resize },
:carousel => Proc.new { |instance| instance.decide_style }
},
:url => "/pictures/:style/:basename.:extension",
:path =>":rails_root/public/pictures/:style/:basename.:extension"
validates_attachment_content_type :photo, :content_type => …Run Code Online (Sandbox Code Playgroud) 我面临一个奇怪的问题.
我有 Post has_many attachments. as: :imageable
和
Attachment belongs_to imageable, polymorphic: true
我正在尝试使用dropzone.js上传附加到单个帖子的多个图像
但是,每当我以dropzone驱动的形式上传多个文件时,每个图像都会作为自己的帖子上传.我上传了4张图片,每张附图都有4张帖子.如何才能将我附加到帖子的所有图片仅与该帖子相关联?
这是posts.js看起来像:
$(document).ready(function(){
// disable auto discover
Dropzone.autoDiscover = false;
// grap our upload form by its id
$("#new_post").dropzone({
// restrict image size to a maximum 1MB
maxFilesize: 1,
// changed the passed param to one accepted by
// our rails app
paramName: "post[attachments_attributes][][picture]",
// show remove links on each image upload
addRemoveLinks: true
});
});
Run Code Online (Sandbox Code Playgroud)
从中创建动作 PostsController
def create
@post = Post.create(post_params)
if …Run Code Online (Sandbox Code Playgroud) 我对我实现的旋转木马采取了不同的方向,选择了bxSlider而不是jCarousel.这是我正在建立的图像库http://rjwcollective.com/equinox/rishi_gallery/eqgall.php
我遇到的问题是当我重置过滤器,或选择不同的过滤器时,滑块不会重置.这是初始负载的代码:
//first load
$.ajax({
type:"POST",
url:"sortbystate.php",
data:"city=&gender=&category=",
success:function(data){
//carousel
$('#thumbs').html(data);
//alert("whoa, careful there!");
$('#thumbs').bxSlider({auto: false, mode:'vertical',
autoControls: false,
autoHover: true,
pager: false,
displaySlideQty: 4,
speed:800,
infiniteLoop: true,
moveSlideQty: 4,
controls: true});
}
});//end ajax
Run Code Online (Sandbox Code Playgroud)
这是处理过滤器更改的代码:
$(".statelist :input").click(function(){
var carousel = $('#thumbs').data('jcarousel');
var state = $('.statelist input:checked').attr('value');
var gender = $('.gender input:checked').attr('value');
var category =$('.category input:checked').attr('value');
$.ajax({
type:"POST",
url:"sortbystate.php",
data:"city="+state+"&gender="+gender+"&category="+category,
success:function(data){
//alert("whoa, careful there!");
$('#thumbs').html(data);
$('#thumbs').bxSlider({auto: false, mode:'vertical',
autoControls: false,
autoHover: true,
pager: false,
displaySlideQty: 4,
speed:800,
infiniteLoop: true, …Run Code Online (Sandbox Code Playgroud)