Stars not appearing.

Why aren’t my stars appearing untill I press refresh?

Posted over 1 year ago by eliza khachatryan
Posted over 1 year ago by eliza khachatryan

I have another issue. I moved the contents of the script tag to application js, and alternatively to restaurants.js but either didn't work. We have script tag in two places: show.html.erb and _form.html.erb. I was wondering in which js files do you place the contents of the script tags for the corresponding files?

1
Posted over 1 year ago by Alex Yang

Please post these questions in the discussion thread beneath the video.

Usually, you place that JavaScript code in any .js file (other than application.js). Make sure to wrap everything like in the example below - this makes sure that the document has finished loading before the JavaScript is run.

$(function() {
...code goes here...
});

1
Posted over 1 year ago by Alex Yang

That's strange...have you followed each of the steps in the 'Convert Numbers to Stars' video? If so, and you're still having trouble, send me a link to your up-to-date GitHub repository and I'll take a look.

In the future, please post course-related troubleshooting questions in the discussion thread beneath the video itself. This will give me more content on where you are in the course, as well as help other students who encounter the same issues. Thanks!

1
Posted over 1 year ago by eliza khachatryan

Thank you! I emailed the Github repo, looking forward for your explanation.

1
Posted over 1 year ago by Alex Yang

Based on the code in your repo and the behavior you're describing, I think the issue is related to turbolinks. The easiest way to confirm this is by removing turbolinks and trying again to see if the problem still exists. To remove turbolinks, remove the gem from your Gemfile, run 'bundle install', remove the turbolinks line from your application.js file, remove any turbolinks references in your application.html.erb file, and restart your server.

If you wish to keep turbolinks but still eliminate the issue, I recommend moving the JavaScript code from the <script> tags in your view page into a JavaScript/CoffeeScript file in your app/assets/javascripts directory. Just make sure to wrap your code with the following:

JavaScript example:
$(document).on('turbolinks:load', function() {
<CODE HERE>
});

CoffeeScript example:
$(document).on "turbolinks:load", ->
<CODE HERE>

More info on this approach in this Stack Overflow link:
http://stackoverflow.com/questions/18770517/rails-4-how-to-use-document-ready-with-turbo-links

Hope that helps!

1
Posted over 1 year ago by eliza khachatryan

Great, thanks. Could you explain how moving js code from script to js/coffee script file eliminates this issue?

1
Posted over 1 year ago by Alex Yang

Not sure if it's been fixed already, but in the past, turbolinks has had difficulty dealing with <script> tags in the body:
https://github.com/turbolinks/turbolinks/issues/9

1
Posted over 1 year ago by eliza khachatryan

Nice! That's great to know. Thanks so much for the prompt responses. I'll dig into it now.

1
Posted over 1 year ago by eliza khachatryan

I have another issue. I moved the contents of the script tag to application js, and alternatively to restaurants.js but either didn't work. We have script tag in two places: show.html.erb and _form.html.erb. I was wondering in which js files do you place the contents of the script tags for the corresponding files?

1