首页 > 解决方案 > 在 html 中的 onclick 方法上将 Rails 对象值设置为 true

问题描述

我在 html(materialize) 中创建了一个复选框,现在单击该复选框后,我想将 Ruby 对象设置为 true。

有没有办法做到这一点。我们也可以使用 Js 吗?我现在什至会准备一个 hacky 解决方案。

#_form.html.erb


<%= form_with(model: export_application, local: true, html: {multipart: true}, id: "export-application-portal") do |form| %>

    <div class="input-field col s12 m12">
        <label>Haben Sie schon einmal Hermesdeckungen genutzt?</label>

        <p>
        <label for="Hermes-y">
            <input type="checkbox" class="yes yes-no-btns"  id="export_application_has_previously_used_hermes_cover" name="export_application[has_previously_used_hermes_cover]" value="true"/>
            <span class="yes yes-no-btns" onclick="previouslyHermesInsuranceUsed()" > Yes</span>
        </label>
        </p>
    </div>

    <div class="input-field col s12 m12">
        <input class="handex-btn" type="submit" name="submit" value="Antrag Shicken">
    </div>
<% end %>

function previouslyHermesInsuranceUsed() {
    var x = document.getElementById("newAtHermesDeckung");
    if (x.style.display === "block") {
        x.style.display = "none";
    }
}




我已经尝试了几个小时,但无济于事。

标签: javascripthtmlruby-on-railsmaterial-design

解决方案


推荐阅读