So, I am using a :remote => true form with the paperclip gem to upload a photo. When I submit the form I just want to refresh the content of a div (which will now contain the uploaded photo).
Rails, however, insists on redirecting me to the path of the action used to process the photo submission. Additionally, there is the issue of actually refreshing the div.
I would like to do it with javascript, but there is no afterSubmit handler or anything. I can’t figure out how to respond to the form submit with javascript either. I tried to do
def add_photo
SomeModel.method_that_processes_and_saves(params)
respond_to do |format|
format.js
end
end
and placing the script in add_photo.js.erb. However, the script is never sent (the browser is asking for html?) How can I get around this?? Its been frustrating me for a whole day now.
Or create
add_photo.js.erband write there any javascript you want.It will work if you’re submitting your form via AJAX (js request), that mean that you should add
:remote => trueoption