I'm taking a quick stab at a light weight file upload facility. There's been quite a few answers on SO regarding using jQuery to upload a file to the server, which I want to avoid. I'm looking at way to upload a file to the server for validation when the file has been selected using plain Javascript (no JS libraries) Key questions are: 1. Why doesn't the AJAX call work? 2. Once the 'Upload' button has been pressed, I'd like to verify on Server end that file name is the same, if the same, do nothing, if different, stop current Server processing, and start anew - is it possible to do that in PHP? Current state of source files are below: html: php file: Solved Use the FormData object from XMLHttpRequest level 2. var formData = new FormData(); var fileInput = document.getElementById('input_file'); var file = fileInput.files[0]; formData.append("thefile", file); request.send(formDat...
I have this "as_json" method in my Post model: def as_json(options={}) super(options.merge(:include => { :comments => { :include => [:user] }, :hashtags => {}, :user => {}, :group => {} })) end I'd like to set a limit attribute in :comments like this: def as_json(options={}) super(options.merge(:include => { :comments => { :include => [:user], :limit => 10 }, :hashtags => {}, :user => {}, :group => {} })) end but it doesn't work. How should I proceed? Solved I think that you have only one possibility. I suppouse that you have a has_many :comments association in your Post model So you can define the next has_many association in your Post model, something like this: has_many :ten_comments, -> { limit(10) }, class_name: "Comment", foreign_key: :post_id And then you will be able to do this in the as_json method: def as_json(options={}) super(options.merge(:include => { :te...