link_to调用页面刷新 - Ruby on Rails

时间:2017-06-06 20:27:51

标签: jquery ruby-on-rails session link-to

我是RoR的新手,这是我在Stack Overflow上的第一篇文章!

我创建了以下功能来开始游戏。 session[@translationsCount]设置为0以呈现'welcome'部分,并且在按下“开始”链接时,应将[:@translationsCount]设置为1以呈现另一部分。但是,当我刷新页面时,[:@ transnslationsCount]增加到1.此问题仅在我包含.click函数后才开始。请帮忙!

“_ welcome.html.erb”

 <h2>WELCOME!</h2>

<h2>Translate from English to: </h2>

<%= collection_select(:language, :language_id, @langArr, :id, :language, {class: "input_standard", id: "languageList"}) %>



<%= link_to "Start", "#", id: "startButton" %>

<script type="text/javascript"> 
    var value = $('#languageList').val()
    console.log("Language selected is " + value)
    console.log("Translations count is " + "<%= session[:@translationsCount] %>")

    var clickFunction = '<%= session[:@translationsCount] %>';

    $('#startButton').click(function(){
        <% session[:@translationsCount] = 1 %>

        console.log("LANGUAGE SELECTED IS" + value)
        <% session[:@languageSelected] %> = value
        console.log("Translations count2 is" + "<%= session[:@translationsCount] %>")
        console.log("<%= session[:@languageSelected] %>")
    });


</script>

0 个答案:

没有答案