0

I have a form

<%= nested_form_for @parent do |p| %>
  <%= p.fields_for :child do |c| %>
    <%= c.check_box :boolean_field %>
  <% end %>
<% end %>

why this check box is not checked when I want to edit a parent record while it is already c.boolean field is set to true and I can see value of text box is set to 1. How can I over come I tried a lot now its annoying me.

0

3 Answers 3

1

<%= c.check_box :boolean_field, :checked => true %> should work.

Sign up to request clarification or add additional context in comments.

5 Comments

what do you see in your inspect element.
seeing a value=1 has nothing to do with checked, It should be something like checked="checked" or true or just checked. try editing the html in your inspect element and putting checked="checked"
I have tried this also but same result when i add attribute in inspect checked='checked'
I don't know how that is possible it works fine for me jsfiddle.net/399fcb4y
you will not believe what kind of mistake is this see my my answer thanks a lot for your attention I am going to up vote for your response.
0

You need to do something like this

<%= c.check_box :boolean_field, :checked => @parent.boolean_field %>

Comments

0

damn mistake some one write this method in a js file

$( document ).ready(function() {
  $('input:checkbox').removeAttr('checked')
});

and its a silly mistake I just removed this and it is working now.

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.