Reputation: 2533
I think I must be doing something stupid. Unfortunately, due to the nature of stupidity, I can't tell what I'm being stupid about. So, as you can guess, I feel pretty stupid.
Please help me surmount this brick wall of stupidity.
I want to be able to click on a submit button and not leave the page, moreover, for that page to not even attempt to reload! This is accomplished by ajax and I've read several guides on it, I have even had it working on another project before. In this instance I'm hiding the div with scriptaculous. In the previous version of ajax form submission I used a (pseudo code)
render update do |page|
page replace html with this div
end
But this time I'm not actually going to replace the div or anything, I'm just hiding it with scriptaculous with an onclick event....
Alls I want is for the form to actually submit and for it to disappear.
So I'm working on a form, here's the form tag:
<%=form_for :call_back_request, :remote => true, :url => {:action => "call_back_request_cbrsent"} do |c| %>
As you can see it is :remote => true
I have various form entry fields, which I think are more or less irrelevant, here's the relevant parts:
This is a field that is part of the submit button, so I've included it here:
<%= hidden_field_tag :instructor_id, "empty", :id=>"instructor_hidden_field" %>
this is the submit button, as you can see I'm using scriptaculous to hide a div, that's the div the the submit button is in.
It could be affecting this so rather than delete that from this stackoverflow question I've included it.
<%=c.submit
:value=>"SEND",
:style=>"width:90px; height:33px; padding-bottom:0; font-size:1em;",
:class=>"lpl-go-button lpl-go-button-submit",
:onclick=>"Effect.BlindUp('cbr_row_#{rp[:name]}'); document.getElementById('instructor_id').value = '#{rp[:instructor_id]}';return false;", :remote=>true %>
(line breaks added by me here to prevent you guys having to scroll right so much)
From the controller :
def call_back_request_cbrsent
@call_back_request = CallBackRequest.new(params[:call_back_request])
@instructor = Instructor.find_by_id(params[:instructor_id])
@call_back_request.instructor_id = params[:instructor_id]
@call_back_request.save
email = UserMailer.create_send_call_back_request(@call_back_request, @instructor)
email.set_content_type("text/html")
UserMailer.deliver(email)
end
Now, the thing is, as far as my tired mind can see the return false; & the remote => true (in the submit tag specifically) do nothing much. My brain's cache is totally chock a block, I am having trouble thinking. Feel like I need to take a step back and stuff cause I'm not seeing the problems here.
Thanks to anyone who takes the effort to get through my ramblings here to give me an answer, I appreciate that I've got a lot of waffle up there. Really sorry. Dead tired. Think Dr. Jonestone said "sorry I didn't have time to write a short one" - bit of that going on here.
Just to clarify, currently I'm getting missing template error on a remote form... I tried adding this
render :nothing => true
But, it iss not working.
It does a good job at rendering a blank page, I don't know what the point in this would be so I am assuming that either it is not working properly for me or it's not appropriate in this context for some reason.
Upvotes: 1
Views: 4289
Reputation: 14750
Try (in your controller)
render :nothing => true
Edit:
Ah, if you had a template error you should've said so.
I just noticed that you want to remove the div also.
So what you want to do, it in your controller:
def call_back_request_cbrsent
....
respond_to do |format|
format.html
format.js
end
end
And then make a call_back_request_cbrsent.js.erb
file in your views. This will contain the javascript to remove that form. It obviously contain something like the following:
$("#form").remove()
...That's in jQuery, but just use whatever javascript you've been using to remove the form.
Upvotes: 3