これは、Ruby on Rails 3 プロジェクトの私のモデルです。
class Faye < ActiveRecord::Base
  def faye_chatroom_token_id
    a = Faye.find_by_sql("SELECT userid FROM chat WHERE id = #{current_profile.id}")
    Digest::MD5.hexdigest(a.first)
  end
end
私はjavascriptでそれを使用する必要があります:
function broadcast(){
  var channel = **Hier I will call the model method**;
  $.ajax({
    type: 'POST',
    url: "http://localhost:9292/faye",
    data: 'message={"channel":"/'+channel+'/chatroom", "data":"1"}',
    dataType: "json",
    xhrFields: {withCredentials: true},
    crossDomain: true,
  });
}
私を助けてください!