user14346436
user14346436

Reputation: 155

How to get javascript in html.erb file to render in rails 4 app?

I have a rails app that I am trying to add OpenTok to. OpenTok uses javascript, and when I go to my view party.html.erb nothing shows up besides the text in my beginning html tags.

<div id="invitation">Invite your friends! Share the url of this page   

localhost:3000/party/<%= @room.id %></div>
<div id="videobox">

</div>
<script src="//static.opentok.com/webrtc/v2.2/js/opentok.min.js" ></script>
<script type="text/javascript">
var apiKey = API_KEY;
var sessionId = <%= @room.sessionId %>;
var token = <%= @tok_token %>;



var session = OT.initSession(apiKey, sessionId);

  session.on("streamCreated", function(event) {
    session.subscribe(event.stream);
  });

  session.connect(token, function(error) {
    var publisher = OT.initPublisher();
    session.publish(publisher);
  });
</script>

</script>

Do I need a seperate javascript file? Thanks for your help.

Upvotes: 0

Views: 748

Answers (2)

Igor Guzak
Igor Guzak

Reputation: 2165

if your OpenTok is related to some DOM elements, maybe you should wrap it to something like:

$(function(){
   ...
});

which will be triggered after loading full page.

Upvotes: 1

AshokGK
AshokGK

Reputation: 875

Two ways you can include the java script

1) Download the java script file and put it in your app(app/assets/javascripts) and add this

<script type="text/javascript" src="/assets/opentok.min.js"></script>

your html.erb file

2)Get it from online

<script type="text/javascript" src="https://static.opentok.com/webrtc/v2.2/js/opentok.min.js"></script>

Upvotes: 0

Related Questions