ユーザーにメールを送信するために、コントローラーで次のアクションを実行しています。
def email_all_users
User.all.each do |u|
if !u.information.nil?
if !u.information.business
UserMailer.candidate_email(u).deliver
else
UserMailer.business_email(u).deliver
end
else
UserMailer.no_info_email(u).deliver
end
end
redirect_to "/users/#{current_user.id}", :flash => { :success => "Los correos fueron enviados" }
end
そして、ここに私の見解のリンクがあります
<%= link_to "Enviar Correos".html_safe, {:controller => "users", :action => "email_all_users"}, :method => "get", :id => "email_users", :html => {:style => "color:#FAA732;" }, :remote => true %>
<span id="loading" style="color:rgb(41, 160, 41);display:none;"><i class="icon-spinner icon-spin"></i> Enviando</span>
<span id="send" style="color:rgb(41, 160, 41);display:none;"><i class="icon-ok-circle"></i> Enviado!</span>
この内容でこのファイル email_all_users.js.erb を作成します
$('#email_users').hide();
$('#email_users').ajaxStart(function() {
$('#loading').show();
});
$('#email_users').ajaxComplete(function() {
$('#loading')..hide();
$('#send')..show();
});
リンクをクリックした後にわかるように、リンクを非表示にして、読み込みスパンにある画像を表示します (読み込みは id です)。アクションが終了したら、読み込みを非表示にして送信スパンを表示します (sendはスパンの ID です)。
アプリをクリックするとメールが送信されますが、リンクが非表示にならず、読み込みと送信が表示されないため、私が間違っていることです。
よろしくお願いいたします。
解決
email_all_users.js.erb を assets フォルダーに移動し、次のように変更しました。
$(document).ajaxStart(function() {
$('#email_users').hide();
$('#loading').show();
});
$(document).ajaxComplete(function() {
$('#loading').hide();
$('#send').show();
});
問題解決。
とにかくありがとう。