0

This is my model in Ruby on Rails 3 project:

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

I need to use it in 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,
  });
}

Please, help me!

Kurt Russell
  • 225
  • 1
  • 3
  • 15

1 Answers1

0

you have to render somewhere into html your channel

<%= hidden_field_tag :channel_id, @faye.faye_chatroom_token_id %>

and than just take it with

$('#channel_id').val();
okliv
  • 3,909
  • 30
  • 47