I am currently working on integrating Angularjs upload functionality into my rails application:
Below is my controller code for managing photos:
def create
@photo = current_user.photos.new(photo_params)
respond_to do |format|
if @photo.save
format.html { redirect_to @photo, notice: 'Photo was successfully created.' }
format.json { render action: 'show', status: :created, location: @photo }
else
format.html { render action: 'new' }
format.json { render json: @photo.errors, status: :unprocessable_entity }
end
end
end
def photo_params
params.require(:photo).permit(:album_id, :user_id, :title, :description, :path)
end
I believe I am nearing a solution. However, I encounter an error when trying to upload:
param is missing or the value is empty: photo
Extracted source (around line #92):
9091929394
# Never trust parameters from the scary internet, only allow the white list through.
def photo_params
params.require(:photo).permit(:album_id, :user_id, :title, :description, :path)
end
end
I suspect that I need to format the data before sending it in a specific way, like this:
{"photo"=>{"tmpname"=>"253", "etc"=>"1"}}
Here's the log from the terminal:
Here is my HTML input:
<input type="file" nv-file-select="" name="photo[path]" id="photo_path" uploader="uploader" multiple /><br/>
The column in my database managed by paperclip gem is named path
I am having difficulty understanding how to implement this in the Angular script.