title: Rails - add a dropdown selection to index with db update on change
body: <p>I've added dropdown selections to forms before, but am having trouble getting them to work in the index view. I've read the API on this and can't get anything to work.</p>
  
  <p>Basically, I've got a list of all tasks in the index view. I set the default in the db to 'No' in a migration. I want to be able to loop through all the tasks and have a dropdown selection appear with the options no, yes and partly. Then I want to be able to have the db update that task's field with the selection when it is made.</p>
  
  <p>I can't get the dropdown to work - whenever I try using task.select, it says that select is a private method. I apologise, I'm fairly new to rails - any help anyone could give would be fantastic! How do I get the dropdown to work and how do I ensure that the db gets updated when the value is changed?</p>
  
  <p>Thanks!</p>
  
  <p>View code (here's what I have so far) - tasks/index:</p>
  
  <pre><code>&lt;table class="table table-striped table-bordered"&gt;
    &lt;tr&gt;
      &lt;th&gt;Name&lt;/th&gt;
      &lt;th&gt;Category&lt;/th&gt;
      &lt;th&gt;Notes&lt;/th&gt;
      &lt;th&gt;Completed?&lt;/th&gt;
      &lt;th&gt;&lt;/th&gt;
      &lt;th&gt;&lt;/th&gt;
      &lt;th&gt;&lt;/th&gt;
    &lt;/tr&gt;
  
  &lt;% @tasks.each do |task| %&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;%= task.name %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= task.category %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= task.notes %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= task.select :complete, ['No','Yes','Partly'], :selected =&gt; 'No' %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= link_to 'Show', task %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= link_to 'Edit', edit_task_path(task) %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= link_to 'Delete', task, confirm: 'Are you sure?', method: :delete %&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;% end %&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>After more research, I've changed the line of code:</p>
  
  <pre><code>&lt;td&gt;&lt;%= task.select :complete, ['No','Yes','Partly'], :selected =&gt; 'No' %&gt;&lt;/td&gt;
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>&lt;% form_for task do |f| %&gt;
      &lt;td&gt;&lt;%= select :task, :complete, [ ["Yes",2], ["Partly",1], ["No",0]] %&gt;&lt;/td&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>This has stopped throwing up errors when I try and load the page, however, there is nothing where the 'form' should be - and nothing in the source code, these lines are skipped. How can I get this form to appear and how can I get it to change the database when the selection is changed? Thanks!</p>