I have few models - User, Teacher and TeacherLeader.
class User < ActiveRecord::Base
attr_accessible ...,
:teacher_attributes
has_one :teacher
has_one :teacher_leader
accepts_nested_attributes_for :teacher_leader
end
class Teacher < ActiveRecord::Base
belongs_to :user
has_one :teacher_leader
end
class TeacherLeader < ActiveRecord::Base
belongs_to :user
belongs_to :teacher
end
I would like to fill TeacherLeader via nested attributes. So, i do such things in controller:
class TeacherLeadersController < ApplicationController
...
def new
@user = User.new
@teacher_leader = @user.build_teacher_leader
@teachers_collection = Teacher.all.collect do |t| [ "#{t.teacher_last_name} #{t.teacher_first_name} #{t.teacher_middle_name}", t.id ]
end
@choosen_teacher = @teachers_collection.first.last unless @teachers_collection.empty?
end
end
And also have such view (new.html.erb):
<%= form_for @user, :url => teacher_leaders_url, :html => {:class => "form-horizontal"} do |f| %>
<%= field_set_tag do %>
<% f.fields_for :teacher_leader do |tl| %>
<div class="control-group">
<%= tl.label :teacher_id, "Teacher names", :class => "control-label" %>
<div class="controls">
<%= select_tag( :teacher_id,
options_for_select( @teachers_collection, @choosen_teacher )) %>
</div>
</div>
<% end %>
<div class="control-group">
<%= f.label :user_login, "Login", :class => "control-label" %>
<div class="controls">
<%= f.text_field :user_login, :placeholder => @everpresent_field_placeholder %>
</div>
</div>
<div class="control-group">
<%= f.label :password, "Pass", :class => "control-label" %>
<div class="controls">
<%= f.text_field :password, :placeholder => @everpresent_field_placeholder %>
</div>
</div>
<% end %>
<%= f.submit "Create", :class => "btn btn-large btn-success" %>
<% end %>
Problem is that select form here does NOT appear. Why? Do i do something wrong?