I have a "payment" form that has a file attachment for upload the receipt_img, i'm using paperclip, angular.js in frontend and ng-file-upload plugin..
everything works fine if the attachment is filled,
but i want to make this attachment as an optional attachment, i have tried many ways in the other same question in this stackoverflow
same-question-1, same-question-2
but no one works on my form, there's always show the error
No handler found for null
Completed 422 Unprocessable Entity in 119ms (Views: 15.4ms | ActiveRecord: 41.7ms)
the things i want to ask are,
is there any method in ng-file-upload plugin that make an attachment is ruquired, so it wouldn't work if empety?
is there any way how to solve it ?
here's my paperclip for receipt image :
has_attached_file :receipt_img, dependent: :destroy
validates_attachment :receipt_img, :content_type => { :content_type => /\Aimage\/.*\Z/ }, :size => { :in => 0..2.megabytes }
and it's my payment.coffee :
Sprangular.service "Payment", ($http, $q, _, Env, Account, Cart, Flash, Upload) ->
service =
confirmPaymentBankTransfer: (order, payment, bankTransfer) ->
url = Spree.mountedAt() + "/api/orders/#{order.number}/payments/#{payment.id}"
bankTransfer.receipt_img.upload = Upload.upload
url: url
method: 'PUT'
headers:
'X-Spree-Order-Token': order.token
data:
payment:
receipt_img: bankTransfer.receipt_img
bank_name: bankTransfer.bank_name
deposited_on: bankTransfer.deposited_on
account_name: bankTransfer.account_name
account_no: bankTransfer.account_no
transaction_reference_no: bankTransfer.transaction_reference_no
our_bank_name: bankTransfer.our_bank_name
# $http.put(url, $.param(params), config)
# .success (response) ->
# Flash.success 'app.account_updated'
# .error (response) ->
# Flash.error 'app.account_update_failed'
service
thanks,
edit add controller.coffee
'use strict'
class Sprangular.BankTransfer
Validity.define @,
deposited_on: 'required'
bank_name: 'required'
account_no: 'required'
transaction_reference_no: 'required'
our_bank_name: 'required'
constructor: (deposited_on=null, bank_name=null, account_name=null, account_no=null, transaction_reference_no=null, our_bank_name=null, receipt_img=null) ->
@deposited_on = deposited_on
@bank_name = bank_name
@account_name = account_name
@account_no = account_no
@transaction_reference_no = transaction_reference_no
@our_bank_name = our_bank_name
@receipt_img = receipt_img
init: ->
@id = @id
@deposited_on = @deposited_on
@bank_name = @bank_name
@account_name = @account_name
@account_no = @account_no
@transaction_reference_no = @transaction_reference_no
@our_bank_name = @our_bank_name
@receipt_img = @receipt_img
same: (other) ->
@id == other.id