0

If a person checkmarks the boolean :someday how can we trigger the conditional?

<%= 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 %>
1
  • Use javascript to show/remove elements based on selected Commented Jun 6, 2016 at 0:05

1 Answer 1

1

When user checks the checkbox, you want to show <%= link_to 'Visit London', create_challenge_path(challenge: {name: 'Visit London', categorization: 'adventure', category: 'goal'}), class: "featured-challenge" %>, otherwise you want to show <%= button_tag(type: 'submit', class: "btn", id: "challenge-button") %>, correct?

I assume that 'Save' button will be visible all the time, and I assume that default state of your checkbox is 'false'.

You can hide .featured-challenge from the screen, and than check in jQuery if the checkbox is checked:

.featured-challenge { display: none; }

Somewhere in your JS (featured-challenge.js maybe):

$(document).ready(function(){
    $('input[type="checkbox"]').click(function(){
        $(".featured-challenge").toggle();
    });
});
Sign up to request clarification or add additional context in comments.

Comments

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.