ruby - How to make Rails app perform an action depending on if a checkbox is checked? (RoR) -


i have checkbox in view called post_form.html.erb uses post. here's full code of below:

<%= form_for @post, :html => {:multipart => true} |f| %>   <%= render 'shared/error_messages', object: @post %>   <div class="field">     <%= f.text_area :content, :cols => 5, :rows => 5 %>   </div>   <div class="itemcontainer">     <div class="iteminput">add photo:<br>   <%= f.file_field :image %> </div><div class="itemcheckbox"> <label for="a">run script?</label>   <div class="itemcheckboxalign"><input type="checkbox" id="a"></div> </div></div><br> <%= f.submit "post", class: "btn btn-large btn-primary" %> <% end %> 

the above used post , use show.html.erb view. can see in above code, there's checkbox during posting process. want if checkbox checked, action happens in show.html.erb view (running script in case). if it's not checked, don't want run script.

is best method store boolean information on whether checkbox checked in database? question is, what's ror code make checkbox associate table value?

you're going want use jquery that:

$('#a').click(function() {   $('#text').toggle(); }); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -