Note that there are some explanatory texts on larger screens.

plurals
  1. PORails:How can I get these check_boxes and radio buttons to show the data from the model?
    primarykey
    data
    text
    <p>Here is some code that is used basically to show a table of listings from my database. Last few columns are nothing but radio buttons and check boxes that are tied to specific boolean attributes of the model. Ive programmed the check boxes and radio buttons. But How do I get them to display the values in the database?</p> <p>index.html.erb:</p> <pre><code>&lt;h1&gt;Listings&lt;/h1&gt; &lt;table class="datatable"&gt; &lt;tr id="heading" &gt; &lt;th &gt;id&lt;/th&gt; &lt;th &gt;name&lt;/th&gt; &lt;th&gt;telephone&lt;/th&gt; &lt;/tr&gt; &lt;% @listings.each do |listing| %&gt; &lt;tr id="body"&gt; &lt;th&gt;&lt;%=listing.id%&gt;&lt;/th&gt; &lt;th&gt;&lt;%= link_to listing.name, edit_listing_path(listing) %&gt;&lt;/th&gt; &lt;th&gt;&lt;%=listing.telephone%&gt;&lt;/th&gt; &lt;%= form_for listing do |f| %&gt; &lt;td id="keep"&gt;&lt;%= f.radio_button :keep, "Keep" %&gt;&lt;/br&gt; &lt;%= f.label :keep, "Keep" %&gt; &lt;/td&gt; &lt;td id="delete"&gt; &lt;%= f.radio_button :keep, "Delete" %&gt;&lt;/br&gt; &lt;%= f.label :keep, "Delete" %&gt; &lt;/td&gt; &lt;td id="checked"&gt;&lt;%= f.check_box :checked %&gt;&lt;/br&gt; &lt;%= f.label :checked, "checked" %&gt; &lt;/td&gt; &lt;td id="collected"&gt;&lt;%= f.check_box :collected %&gt;&lt;/br&gt; &lt;%= f.label :collected, "collected" %&gt; &lt;/td&gt; &lt;td id="digitized"&gt;&lt;%= f.check_box digitized %&gt;&lt;/br&gt; &lt;%= f.label :digitized, "digitized" %&gt; &lt;/td&gt; &lt;td id="in_db"&gt;&lt;%= f.check_box :in_database %&gt;&lt;/br&gt; &lt;%= f.label :database, "database" %&gt; &lt;/td&gt; &lt;td id="submit"&gt;&lt;%= f.submit "update" %&gt;&lt;/br&gt; &lt;/td&gt; &lt;% end %&gt; &lt;/tr&gt; &lt;% end %&gt; &lt;/table&gt; </code></pre> <p>Also the reason Im choosing the "form" here is because eventually after I figure out how to show the data here, Id like to have this view also "update" the data in the model if the user changes any values in the checkboxes. But, Ill get to that once Ive learnt how to display the model's values.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload