Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.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
JQuery文件上传,Ruby on Rails,显示错误。完整消息_Jquery_Ruby On Rails - Fatal编程技术网

JQuery文件上传,Ruby on Rails,显示错误。完整消息

JQuery文件上传,Ruby on Rails,显示错误。完整消息,jquery,ruby-on-rails,Jquery,Ruby On Rails,我正在使用,我需要打印错误消息,以便用户可以通过上载文件(错误的大小、文件名)来理解错误发生的原因 我不知道如何将其集成到代码中 如果有人给我一个提示,我将不胜感激 我的验证: validates :upload_file_name, :presence => true, :format =>{:with => %r{\.(cel)$}i} validates_uniqueness_of :up

我正在使用,我需要打印错误消息,以便用户可以通过上载文件(错误的大小、文件名)来理解错误发生的原因

我不知道如何将其集成到代码中

如果有人给我一个提示,我将不胜感激

我的验证:

validates :upload_file_name,  :presence   => true,
                                :format     =>{:with => %r{\.(cel)$}i}

  validates_uniqueness_of :upload_file_name, :message => "blabla"

  validates :upload_file_size,  :inclusion  => {:in =>10.megabytes..20.megabytes}
index.html.erb:

<script id="template-upload" type="text/x-tmpl">
  {% for (var i=0, file; file=o.files[i]; i++) { %}
  <tr class="template-upload fade">
    <td class="preview"><span class="fade"></span></td>
    <td class="name"><span>{%=file.name%}</span></td>
    <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
    {% if (file.error) { %}
    <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
    {% } else if (o.files.valid && !i) { %}

    <td class="start">{% if (!o.options.autoUpload) { %}
      <button class="btn btn-mini btn-primary">
        <i class="icon-upload icon-white"></i>
        <span>{%=locale.fileupload.start%}</span>
      </button>
      {% } %}</td>
    {% } else { %}
    <td colspan="2"></td>
    {% } %}
    <td class="cancel">{% if (!i) { %}
      <button class="btn btn-mini btn-warning">
        <i class="icon-ban-circle icon-white"></i>
        <span>{%=locale.fileupload.cancel%}</span>
      </button>
      {% } %}</td>
  </tr>
  {% } %}
</script>
<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">
  {% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download fade">
      {% if (file.error) { %}
        <td></td>
        <td class="name"><span>{%=file.name%}</span></td>
        <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
        <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
        <ul>
        <% file.errors.full_messages.each do |msg| %>
         <li>*<%=msg %></li>
         <% end%>
         </ukl
        {% } else { %}
        <td class="preview">{% if (file.thumbnail_url) { %}
          <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
          {% } %}</td>
        <td class="name">
          <a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
        </td>
        <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
        <td colspan="2"></td>
        {% } %}
      <td class="delete">
        <button class="btn btn-mini btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
          <i class="icon-trash icon-white"></i>
          <span>{%=locale.fileupload.destroy%}</span>
        </button>
        <input type="checkbox" name="delete" value="1">
      </td>
    </tr>
    {% } %}
</script>

你解决问题了吗?
def create
    p_attr=params[:upload]
    p_attr[:upload] = params[:upload][:upload].first if params[:upload][:upload].class == Array
    @upload = Upload.new(p_attr)

    respond_to do |format|
      if @upload.save
        format.html {
          render :json => [@upload.to_jq_upload].to_json,
          :content_type => 'text/html',
          :layout => false
        }
        format.json { render json: [@upload.to_jq_upload].to_json, status: :created, location: @upload }
      else
        format.html { render action: "new" }
        format.json { render json: @upload.errors, status: :unprocessable_entity }
      end
    end
  end