Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有Rails 4.0嵌套资源的jQuery文件上载程序_Jquery_Ruby On Rails_Ruby On Rails 4_Nested Forms_Jquery File Upload - Fatal编程技术网

带有Rails 4.0嵌套资源的jQuery文件上载程序

带有Rails 4.0嵌套资源的jQuery文件上载程序,jquery,ruby-on-rails,ruby-on-rails-4,nested-forms,jquery-file-upload,Jquery,Ruby On Rails,Ruby On Rails 4,Nested Forms,Jquery File Upload,我有一个应用程序,有一个画廊,有很多:画廊图片 我跟踪了Ryan Bates,并上传了多张图片。我遇到的问题是获取create.js.erb文件以自动刷新页面。这是我得到的 gallery.rb class Gallery < ActiveRecord::Base has_many :gallery_images, dependent: :destroy end class GalleryImage < ActiveRecord::Base belongs_to :gall

我有一个应用程序,有一个画廊,有很多:画廊图片

我跟踪了Ryan Bates,并上传了多张图片。我遇到的问题是获取create.js.erb文件以自动刷新页面。这是我得到的

gallery.rb

class Gallery < ActiveRecord::Base
  has_many :gallery_images, dependent: :destroy
end
class GalleryImage < ActiveRecord::Base
  belongs_to :gallery
  has_attached_file :image, 
                    :styles => { :original => "1600x1600>",
                                 :thumb => "100x100#" }, 
                                 :default_url => "/images/:style/missing.png"

  validates_attachment :image,
                       :presence => true,
                       :content_type => { :content_type => ['image/jpeg'] }
end
class GalleryImagesController < ApplicationController

  def create
    if signed_in?
      @gallery = Gallery.friendly.find(params[:gallery_id])
      @image = @gallery.gallery_images.create(gallery_image_params)
      redirect_to gallery_path(@gallery)
    else
      @gallery = Gallery.friendly.find(params[:gallery_id])
      redirect_to signin_url, notice: "Please sign in to add an image."
      session[:return_to] = gallery_path(@gallery)
    end
  end

  def destroy
    @gallery = Gallery.friendly.find(params[:gallery_id])
    @image = @gallery.gallery_images.find(params[:id])
    @image.destroy
    flash[:notice] = "Image removed."
    redirect_to gallery_path(@gallery)
  end

  private

    def gallery_image_params
      params.require(:gallery_image).permit(:image)
    end
end
<div id="links">
  <%= render @gallery.gallery_images %>
</div>

<% if current_user && current_user.admin? %>
  <%= render "gallery_images/form" %>
<% end %>
<%= form_for [@gallery, @gallery.gallery_images.new], html: { multipart: true } do |f| %>
  <%= f.label :image, "Upload Image:" %>
  <%= f.file_field :image, multiple: true, name: "gallery_image[image]" %>      
<% end %>
<% if @image.new_record? %>
  alert("Failed to upload image");
<% else %>
  $("#links").append("<%= j render(@image) %>");
<% end %>
查看/gallery\u图像/create.js.erb

class Gallery < ActiveRecord::Base
  has_many :gallery_images, dependent: :destroy
end
class GalleryImage < ActiveRecord::Base
  belongs_to :gallery
  has_attached_file :image, 
                    :styles => { :original => "1600x1600>",
                                 :thumb => "100x100#" }, 
                                 :default_url => "/images/:style/missing.png"

  validates_attachment :image,
                       :presence => true,
                       :content_type => { :content_type => ['image/jpeg'] }
end
class GalleryImagesController < ApplicationController

  def create
    if signed_in?
      @gallery = Gallery.friendly.find(params[:gallery_id])
      @image = @gallery.gallery_images.create(gallery_image_params)
      redirect_to gallery_path(@gallery)
    else
      @gallery = Gallery.friendly.find(params[:gallery_id])
      redirect_to signin_url, notice: "Please sign in to add an image."
      session[:return_to] = gallery_path(@gallery)
    end
  end

  def destroy
    @gallery = Gallery.friendly.find(params[:gallery_id])
    @image = @gallery.gallery_images.find(params[:id])
    @image.destroy
    flash[:notice] = "Image removed."
    redirect_to gallery_path(@gallery)
  end

  private

    def gallery_image_params
      params.require(:gallery_image).permit(:image)
    end
end
<div id="links">
  <%= render @gallery.gallery_images %>
</div>

<% if current_user && current_user.admin? %>
  <%= render "gallery_images/form" %>
<% end %>
<%= form_for [@gallery, @gallery.gallery_images.new], html: { multipart: true } do |f| %>
  <%= f.label :image, "Upload Image:" %>
  <%= f.file_field :image, multiple: true, name: "gallery_image[image]" %>      
<% end %>
<% if @image.new_record? %>
  alert("Failed to upload image");
<% else %>
  $("#links").append("<%= j render(@image) %>");
<% end %>

警报(“上传图像失败”);
$(“#链接”)。追加(“”);

谢谢您的帮助。

那么您需要控制器中的remote:true还是respond\u with:javascript块


看起来它只是将重定向回页面,并且从未实际使用create.js.erb模板。

您是否有任何错误,或者什么都没有发生?没有错误,它上载所有文件,并且没有加载栏。