Note that there are some explanatory texts on larger screens.

plurals
  1. PORename file uploaded Ruby On Rails
    primarykey
    data
    text
    <p>I use the jquery-multiupload-rails for create a multi upload.</p> <p>So that work but when i want modify the title of my file, the title was use is the same for the 2 files and not title 1 for file 1 and title 2 for file 2 etc....</p> <p>I use javascript for do this.</p> <p>My form was in the javascript</p> <pre><code>&lt;%= form_for Sound.new , :html =&gt; { :multipart =&gt; true, :id =&gt; "fileupload" } do |f| %&gt; &lt;!-- Redirect browsers with JavaScript disabled to the origin page --&gt; &lt;noscript&gt;&lt;input type="hidden" name="redirect" value="http://blueimp.github.io/jQuery-File-Upload/"&gt;&lt;/noscript&gt; &lt;!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload --&gt; &lt;div class="row fileupload-buttonbar"&gt; &lt;div class="span7"&gt; &lt;!-- The fileinput-button span is used to style the file input field as button --&gt; &lt;span class="btn btn-success fileinput-button"&gt; &lt;i class="icon-plus icon-white"&gt;&lt;/i&gt; &lt;span&gt;Add files...&lt;/span&gt; &lt;%= f.file_field :file, multiple: true, id: 'upload-field' %&gt; &lt;/span&gt; &lt;button type="submit" class="btn btn-primary start"&gt; &lt;i class="icon-upload icon-white"&gt;&lt;/i&gt; &lt;span&gt;Start upload&lt;/span&gt; &lt;/button&gt; &lt;button type="reset" class="btn btn-warning cancel"&gt; &lt;i class="icon-ban-circle icon-white"&gt;&lt;/i&gt; &lt;span&gt;Cancel upload&lt;/span&gt; &lt;/button&gt; &lt;button type="button" class="btn btn-danger delete"&gt; &lt;i class="icon-trash icon-white"&gt;&lt;/i&gt; &lt;span&gt;Delete&lt;/span&gt; &lt;/button&gt; &lt;!-- The template to display files available for upload --&gt; &lt;script id="template-upload" type="text/x-tmpl"&gt; {% for (var i=0, file; file=o.files[i]; i++) { %} &lt;tr class="template-upload fade"&gt; &lt;td class="preview"&gt;&lt;span class="fade"&gt;&lt;/span&gt;&lt;/td&gt; &lt;td class="name"&gt;&lt;span&gt;{%=file.name%}&lt;/span&gt;&lt;/td&gt; &lt;td class="title"&gt;&lt;input name="title[]" value='{%=file.name%}' required&gt;&lt;/td&gt; &lt;td class="size"&gt;&lt;span&gt;{%=o.formatFileSize(file.size)%}&lt;/span&gt;&lt;/td&gt; </code></pre> <p>I know my mistake is in this line : If I use title[] , so for 2 file , the title is "title1,title2". and if I just use title for 2 files, the files 1 and the files 2 have the "title2" only.</p> <pre><code>&lt;td class="title"&gt;&lt;input name="title[]" value='{%=file.name%}' required&gt;&lt;/td&gt; </code></pre> <p>And my controller#create</p> <pre><code>def create @sound = Sound.new(params[:sound]) @sound.title = params[:title].to_s.gsub(/\[|\]|"/,'') respond_to do |format| if @sound.save redirect_to sounds_path else format.html { render action: "new" } format.json { render json: @sound.errors, status: :unprocessable_entity } end end end </code></pre> <p><strong>Console</strong></p> <pre><code> Started POST "/sounds" for 127.0.0.1 at 2013-12-17 17:59:09 +0100 Processing by SoundsController#create as JSON Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"Ke1wOlf1z+eoQ6cS0lpQraqsiiU0BXoT2VtFweGed18=", "title"=&gt;"309060_4371516803467_1048226528_n.jpg", "sound"=&gt;{"file"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x007fa626cbff88 @original_filename="14591_4925922503263_818636474_n.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"sound[file]\"; filename=\"14591_4925922503263_818636474_n.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#&lt;File:/var/folders/sj/sr703c8n6llc198jfg6746d40000gn/T/RackMultipart20131217-2706-itxsfb&gt;&gt;}} (0.1ms) begin transaction SQL (0.6ms) INSERT INTO "sounds" ("created_at", "file", "name", "title", "updated_at") VALUES (?, ?, ?, ?, ?) [["created_at", Tue, 17 Dec 2013 16:59:09 UTC +00:00], ["file", "14591_4925922503263_818636474_n.jpg"], ["name", nil], ["title", "309060_4371516803467_1048226528_n.jpg"], ["updated_at", Tue, 17 Dec 2013 16:59:09 UTC +00:00]] (1.1ms) commit transaction Redirected to http://localhost:3000/sounds Completed 406 Not Acceptable in 14ms (ActiveRecord: 1.8ms) Started POST "/sounds" for 127.0.0.1 at 2013-12-17 17:59:09 +0100 Processing by SoundsController#create as JSON Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"Ke1wOlf1z+eoQ6cS0lpQraqsiiU0BXoT2VtFweGed18=", "title"=&gt;"309060_4371516803467_1048226528_n.jpg", "sound"=&gt;{"file"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x007fa625a8d9a0 @original_filename="25490_392719757235_767862235_3946737_600749_n.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"sound[file]\"; filename=\"25490_392719757235_767862235_3946737_600749_n.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#&lt;File:/var/folders/sj/sr703c8n6llc198jfg6746d40000gn/T/RackMultipart20131217-2706-d32r2a&gt;&gt;}} (0.1ms) begin transaction SQL (0.4ms) INSERT INTO "sounds" ("created_at", "file", "name", "title", "updated_at") VALUES (?, ?, ?, ?, ?) [["created_at", Tue, 17 Dec 2013 16:59:09 UTC +00:00], ["file", "25490_392719757235_767862235_3946737_600749_n.jpg"], ["name", nil], ["title", "309060_4371516803467_1048226528_n.jpg"], ["updated_at", Tue, 17 Dec 2013 16:59:09 UTC +00:00]] (2.0ms) commit transaction Redirected to http://localhost:3000/sounds Completed 406 Not Acceptable in 8ms (ActiveRecord: 2.4ms) </code></pre> <p>Thank for your help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload