Thanks for your time!
I get routes in routes.rb:
get "loadreport/test"
post "loadreport/update"
The test function in loadreport controller is an empty function:
def test
end
The test.html.erb contains:
<form action="/loadreport/update?method=post" class="button_to" method="post">
<div>
<input type="submit" value="Update" />
<textarea cols="30" id="post_body" name="comments" rows="5" maxlength=200>
</textarea>
</div>
</form>
The update function will update database:
def update
some_database.update(params[:comments])
end
Now when I click the Update button in test.html.erb, it will call /loadreport/update , and jump to update.html.erb. As update.html.erb doesn’t exist, server will give me errors like : Template is missing ... blah ...
What I want to achieve is: when I click the Update button in test.html.erb, it will simply call /loadreport/updateto update database, and then pop up a message box which says “update successful!”, instead of jumping to another page.
How to change my code to achieve that? Can anyone give me some idea or some links on this topic. Thanks!
You can make a Ajax post and get the return and show an alert. Try jQuery.
Or try:
This will redirect to the previous page.