lundi 27 juin 2016

Populating checkboxes with data from database table

I'm trying to create a form with a series of checkboxes where the name and text value links to an attribute within a table and displays the text from the topic entries in the recommends table. The view in which I wish to have this form is in located within search folder and as such the search controller has been updated to include:

 def new 
     @topic = Recommend.new
  end  

and:

def new
@topic = Recommend.all.select(:topic).
end

The table has a column named topic and is populated with data such as medicine. Ideally the code would return a series of the below example for each of the entries:

<%= form_for @topic do |f| %>
  <%= f.check_box :topic %>
  <%= f.check_box :body, size: "60x12" %>
  <%= f.submit "Create" %>
<% end %>    




Aucun commentaire:

Enregistrer un commentaire