私が探しているのは、ページのバックグラウンドで実行されるajaxスクリプトを取得し、データベースに新しいレコードがあるかどうかを確認し、私のページにそれを記録して表示する。Ruby on rails live update
私はまた、私はそれを行う方法を学ぶことを好むとiがかなり新しい未来
イムで別の何かのためにそれを必要とする場合、変更を行うことが容易と私はむしろこれを自分で行うだろうプラグインを使用する必要はありませんレール上でAJAXとルビーはそう説明するのビットは、IAユーザーが爽やかな、それはページなしで変更内容を更新しますが、私は何をしたいが、それはまた、新しいデータ
class NotificationsController < ApplicationController
# GET /notifications
# GET /notifications.json
def index
@notifications = Notification.all
end
def show
end
def update
@notification = Notification.find(params[:id])
@notification.update_attributes(:content => params[:content][:content])
respond_to do |format|
format.html { redirect_to notifications_path }
format.json { render json: @notification}
end
end
end
を取得するときにこれは私のコントローラが現在ある
順であってもよく、
これはjsファイルです電子
$(document).ready(function(){
$('input[type=submit]').on('click', function(event){
var form = $(this).parent('form');
event.preventDefault();
$.ajax({
type:"POST",
url: form.attr('action'),
data: form.serialize(),
success: function(data){
console.log('this worked')
$('#'+ data.id).html(data.content)
},
error: function(data){
console.log('failed')
},
dataType: 'JSON'
});
});
});
とイムはわからない私はアヤックスか何かを介してこれを行うには持っているつもりです場合ので、あなたが、私はまだアクションを作成行っていない伝えることができるように、これは私のhtmlファイル
<% content_for :titleheader do %>
NOTIFICATIONS
<% end %>
<h1>Listing Notifications</h1>
<% @notifications.each do |notification| %>
<%= form_for notification do |f| %>
<%= notification.id %>
<div id="<%= notification.id %>"><%=notification.content %></div>
<%= notification.read %>
<%= text_field "content", "content" %>
<%= f.submit "change status" %>
<% end %>
<% end %>
です
ヘルプが非常にはいあなたはポーリングと呼ばれるプロセスを使用してAJAXを介してこれを実行する必要があります
これは悪い質問ですか、誰も答えを知らないですか? – Ray