0

I know that there have been some questions regarding Javascript not working in Heroku due to asset pipeline compilation problems etc ... which is way above my head.

I just wanted to add a simple link (see below) to my simple application built with Middleman which should reload page onclick and in turn trigger shuffle! method:

<a href="javascript:;" onClick="window.location.reload()">Click to refresh</a>

Is that even possible? It works fine locally, but no longer works when I push to Heroku. Any thoughts/help appreciated thanks.

Here is a link to the actual app on Heroku: http://coastguard-quiz.herokuapp.com/

My index.html.erb code is below:

---
title: Coast Guard Quiz
---

<h1>Coast Guard Rank Quiz</h1>

<h3>Guess the enlisted insignia below:</h3>

<%

seaman_recruit = {
    img: "<img src = 'images/USCG_SR.png'>",
    name: "Seaman Recruit",
    en_class: "Seaman",
}

seaman_apprentice = {
    img: "<img src = 'images/USCG_SA.png'>",
    name: "Seaman Apprentice",
    en_class: "Seaman",
}

seaman = {
    img:  "<img src = 'images/USCG_SM.png'>",
    name: "Seaman",
    en_class: "Seaman",
    abbr: "SN",
    title:"Seaman (last name)",
    paygrade: "E3"
}

ranks = [seaman_recruit, seaman_apprentice, seaman, pettyofficer3, pettyofficer2, pettyofficer1]

current_rank = ranks.shuffle!.first

img_now = current_rank[:img]
name_now = current_rank[:name]
class_now = current_rank[:en_class]
abbr_now = current_rank[:abbr]
title_now = current_rank[:title]
paygrade_now = current_rank[:paygrade]

%>

<div id="container" class="shadow">

    <p><%= img_now %></p>
    <div id="hideaway" style="display:none;">
        <p class="bld"><%= name_now %></p>
        <p><%= class_now %></p>
        <p><%= abbr_now %></p>
        <p><%= title_now %></p>
        <p><%= paygrade_now %></p>
        <a href="javascript:;" onClick="document.getElementById('hideaway').style.display='none'; document.getElementById('showme').style.display='block'">Hide Answer</a>
    </div>

    <div id="showme">
    <a class="show" href="javascript:;" onClick="document.getElementById('hideaway').style.display='block'; document.getElementById('showme').style.display='none';">Get answer</a>
    </div>

</div>

<a href="javascript:;" onClick="window.location.reload()">Click to refresh</a>
5
  • Please post the source-code of the current page. We need to see the code that gets executed by the browser, not the code sent to the browser. Commented Feb 24, 2013 at 18:49
  • onClick="window.location.href=window.location" - should solve your issue Commented Feb 24, 2013 at 19:00
  • As a side note, please don't set variables in the view. All the code before the id="container" is responsibility of the controller, not the view. Commented Feb 24, 2013 at 19:01
  • The link you posted works perfectly for me with Google Chrome. Commented Feb 24, 2013 at 19:02
  • it works on MAC OS Safari Commented Feb 24, 2013 at 19:03

1 Answer 1

2

Given how simple is the string, I don't think this is the source of your problem. It's more likely the minification of the assets messed up your JS and there is a JS error somewhere before the code is evaluated causing the JS to not work.

I suggest you to open the page with a JavaScript developer tool (such as Google Chrome JS console) and check if there is any error logged in the console.


UPDATE: The link you posted works perfectly for me with Google Chrome.

Sign up to request clarification or add additional context in comments.

3 Comments

@SteAp here are the contents of my index.html.erb file. Thanks everyone who responded so far.
does this work if it's like this? <a href="#" onClick="window.location.reload()">Click to refresh</a>
Looking back it actually was not a Javascript issue ... rather a Middleman issue. My mistake. Thanks all for your comments though!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.