如果一个人检查布尔:someday,我们如何触发条件?
<%= simple_form_for(@challenge, html: { data: { modal: true } }) do |f| %>
<%= f.check_box :someday %> # If checkmarked show first condition else show second condition
<% if :someday == true %> # How to Write this line?
<%= link_to 'Visit London', create_challenge_path(challenge: {name: 'Visit London', categorization: 'adventure', category: 'goal'}), class: "featured-challenge" %>
<% else %>
<%= button_tag(type: 'submit', class: "btn", id: "challenge-button") do %>
Save
<% end %>
<% end %>发布于 2016-06-06 03:49:17
当用户选中复选框时,要显示<%= link_to 'Visit London', create_challenge_path(challenge: {name: 'Visit London', categorization: 'adventure', category: 'goal'}), class: "featured-challenge" %>,否则要显示<%= button_tag(type: 'submit', class: "btn", id: "challenge-button") %>,对吗?
我假设“Save”按钮将始终可见,并且假设复选框的默认状态为'false‘。
您可以将.featured-challenge隐藏在屏幕上,如果选中了复选框,则不需要签入jQuery:
.featured-challenge { display: none; }在您的JS中的某个位置(也许是具有挑战性的.JS):
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
$(".featured-challenge").toggle();
});
});https://stackoverflow.com/questions/37646613
复制相似问题