I created a user and program table, and a joined table. Each user has_and_belongs_to_many :programs and each program has_and_belongs_to_many :user.
Using dropdown select, I wanted to select a program and save it to the user. But after I save, the display always shows the text "Program" instead of the actual program name that was selected from the dropdown.
Dropdown select form:
<%= f.collection_select(:program_ids, Program.all, :id, :name, :include_blank => "Choose a Program" ) %>
Display programs that the user belongs to:
<% @user.programs.each do |program| %>
<%= program.name %>
<% end %>
I'm not sure if I am saving the program to user correctly or if I am displaying the variable wrong. I followed the idea from how to have a dropdown select field in a rails form.
Any suggestion will help, Thanks!