Answer the question
In order to leave comments, you need to log in
How to send a message without reloading the page (Ruby on Rails)?
The page has a div with CSS property display: none; When you click on it, here, a block with two fields for entering values \u200b\u200bis shown (Gender and Age). If you click "Submit data", then the data simply goes away, leaving behind the same div block with the property display: block;
How can I make it so that when a message is sent, the block closes and a message about successful sending is displayed in its place? No page reload.
Answer the question
In order to leave comments, you need to log in
In a simplified form, this is how it is.
In the view:
<div class="msg"></div>
<div class="form-wrap" style="display:block">
<%= form_tag('/feedback', remote: true, format: :json, id: 'feedback') do %>
....
def send_email
....
respond_to do |format|
# if success
msg = success ? 'You request will be success processed'
: 'Ooops. Error occurred. Try later.'
format.json { render json: {msg: msg}.to_json }
end
end
$('#feedback')
.on 'ajax:before', ()->
$('.form-wrap').hide()
$('.msg').html('Sending...')
.on 'ajax:success', (e, data)->
$('.msg').html(data.msg)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question