如何为带有id的rails路由别名?

时间:2016-11-21 12:59:07

标签: ruby-on-rails routes

我有这些路线:

<script>
    window.onload = function() {
        document.addEventListener("deviceready", init, false);
    }

    function init() {
        document.getElementById("btnSave").addEventListener("click", saveData, false);
        document.getElementById("btnGet").addEventListener("click", getData, false);
    }

    function getData() {
        var email1 = document.getElementById("email1").value;
        var pass1 = document.getElementById("password1").value;
        var email2 = window.localStorage.getItem("email");
        var pass2 = window.localStorage.getItem("pass");
        if (email1 == email2 && pass1 == pass2) {
            alert("Login successfully");
            window.location.href = "/b.html";
        } else {
            alert("Invalid login credentials");
        }
    }
</script>
<form class="login-form">
    <input type="email" id="email1" name="email1" placeholder="Email Address" required/>
    <input type="password" id="password1" name="password1" placeholder="Password" required/>
    <button id="btnGet" type="submit" name="submit">Login</button>
</form>

重定向路由执行301到/ welcome / 1.

我没有进行重定向,而是希望只执行id为1的用户#welcome。

我该怎么做?

2 个答案:

答案 0 :(得分:1)

你需要:

    try {

        byte[] encoded = Files.readAllBytes(Paths.get(getClass().getResource("/files/game.json").getFile()));
        return new String(encoded);

    } catch (Exception e) {
        return "";
    }

答案 1 :(得分:0)

您可以为路径指定路径名,并将id作为参数传递给您。

得到欢迎/:id&#39; =&GT; &#39;用户#welcome&#39;,as :: welcome

并将id作为参数传递给

&#39;&lt;%= link_to&#39;按钮&#39;,welcome_path(id)%&gt;&#39;