Rails 4 - jQuery File Upload - SyntaxError: Unexpected token $ -
i having issue jquery file upload , rails 4. appears working except one thing! files uploaded , data posted database. but, following error upon uploading or "creating":
syntaxerror: unexpected token $
my guess: think has wanting receive json back, don't know how achieve or put it. great!
here have:
create.js.erb
<% if @choice.new_record? %> alert("failed upload image: <%= j @choice.errors.full_messages.join(', ').html_safe %>"); <% else %> $("#paintings").append("<%= j render(@choice) %>"); <% end %>
index.html.erb
<h1>choices gallery</h1> <div id="paintings"> <%= render @choices %> </div> <div class="clear"></div> <div class="container"> <h2>upload file</h2> <%= form_for choice.new, :html => { :multipart => true, :id => "fileupload" } |f| %> <!-- fileupload-buttonbar contains buttons add/delete files , start/cancel upload --> <div class="row fileupload-buttonbar"> <div class="span7"> <!-- fileinput-button span used style file input field button --> <span class="btn btn-success fileinput-button"> <i class="icon-plus icon-white"></i> <span>add files...</span> <%= f.file_field :image, multiple: true, name: "choice[image]" %> </span> <button type="submit" class="btn btn-primary start"> <i class="icon-upload icon-white"></i> <span>start upload</span> </button> <button type="reset" class="btn btn-warning cancel"> <i class="icon-ban-circle icon-white"></i> <span>cancel upload</span> </button> <button type="button" class="btn btn-danger delete"> <i class="icon-trash icon-white"></i> <span>delete</span> </button> <input type="checkbox" class="toggle"> </div> <div class="span5"> <!-- global progress bar --> <div class="progress progress-success progress-striped active fade"> <div class="bar" style="width:0%;"></div> </div> </div> </div> <!-- loading indicator shown during image processing --> <div class="fileupload-loading"></div> <br> <!-- table listing files available upload/download --> <table class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody> </table>
choices_controller.rb
class choicescontroller < applicationcontroller def index @choices = choice.all end def show @choice = choice.find(params[:id]) end def new @choice = choice.new end def create @choice = choice.create(choice_params) end end
update #1 first, forgot mention using carrierwave. second, here console giving back: (you can see adds db no problem. there seems error after it's uploaded).
started post "/choices" 127.0.0.1 @ 2013-08-15 15:07:45 -0700 processing choicescontroller#create json parameters: {"utf8"=>"✓", "authenticity_token"=>"ikxddhtabu/hy/qqek9jxr9njltiqmgwu6tuzeme7pm=", "choice"=>{"image"=>#<actiondispatch::http::uploadedfile:0x007fe3f2c50818 @tempfile=#<tempfile:/var/folders/z6/c199lpm13492b758r5xx0ngm0000gn/t/rackmultipart20130815-28015-ngm6w2>, @original_filename="speech_teacher.jpg", @content_type="image/jpeg", @headers="content-disposition: form-data; name=\"choice[image]\"; filename=\"speech_teacher.jpg\"\r\ncontent-type: image/jpeg\r\n">}} (0.2ms) begin sql (26.4ms) insert `choices` (`created_at`, `image`, `name`, `updated_at`) values ('2013-08-15 22:07:45', 'speech_teacher.jpg', 'speech teacher', '2013-08-15 22:07:45') (0.4ms) commit redirected http://localhost:3000/choices completed 302 found in 75ms (activerecord: 27.0ms) started "/choices" 127.0.0.1 @ 2013-08-15 15:07:45 -0700 processing choicescontroller#index json choice load (1.7ms) select `choices`.* `choices` rendered choices/_choice.html.erb (2.5ms) rendered choices/index.html.erb within layouts/application (13.0ms) completed 200 ok in 109ms (views: 106.2ms | activerecord: 1.7ms)
Comments
Post a Comment