nel controller di teacher ho le seguenti righe (salvo nell'oggetto @teacher tutto quello
che c'è in params...)
def create
@teacher = Teacher.new(params[:teacher])
@teacher.save
if @teacher.save
flash[:notice] = 'Form memorizzato!'
redirect_to teachers_path
else
render :action => 'new'
end
end
def new
if session[:user_id]
@current_user = User.find_by_id(session[:user_id])
end
@discipline = Discipline.find(:all)
@teacher = Teacher.new
end
nella vista new di teacher ho:
<%= error_messages_for 'teacher' %>
<h1>Inserimento nuovi insegnanti:</h1>
<% form_for @teacher do |f| %>
cognome: <%= f.text_field :cognome %>
</p>
nome: <%= f.text_field :nome %>
</p>
materia:
<select name="materia">
<% for discipline in @discipline %>
<option value= "<%=h discipline.id %>" <%=h discipline.descrizione %>
</option>
<% end %>
</select>
</p>
<%= submit_tag "Salva insegnante" %>
</p>
<% end %>
devo salvare il dato selezionato nella option (che non è di teacher)...
Grazie

Rispondi quotando