Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7754493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:19:18+00:00 2026-06-01T12:19:18+00:00

I have few models – User , Teacher and TeacherLeader . class User <

  • 0

I have few models – User, Teacher and TeacherLeader.

class User < ActiveRecord::Base                                                              
  attr_accessor   :password                                                              
  attr_accessible :user_login,                                                            
                  :password,
                  :teacher_attributes,
                  :teacher_leader_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 want to save data in TeacherLeader via nested attributes. So, in User model i added accepts_nested_attributes_for :teacher_leader and attr_accessible :teacher_leader_attributes.

Also i have 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

  def create
    user = User.new( params )
    user.user_role = "class_head"

    if user.save
      flash[:success] = "Successfully created class head!"
    else
      flash[:error] = user.errors.full_messages
    end
  end
end

Also i i have view for TeacherLeader controller (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 %>
    </div>
  </div>

  <div class="control-group">
    <%= f.label :password, "Pass", :class => "control-label" %>
    <div class="controls">
      <%= f.text_field :password %>
    </div>
  </div>  
  <% end %>

<%= f.submit "Create", :class => "btn btn-large btn-success" %>

When i’m trying to save my models, i get strange errors such “User login can’t be empty” and others. I know that validations of User models generate them (i don’t know why, i get such errors even if have values in params). I suppose, that i do something wrong in view, because after submiting i have such params:

teacher_id: '1'
user: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
  user_login: schoolh_1rF32
  password: txaqxuTXz96auhX
commit: Create
action: create
controller: teacher_leaders 

But i should have something like this:

user: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
      user_login: schoolh_1rF32
      password: txaqxuTXz96auhX
      teacher_leader_attributes: 
        teacher_id: '1'

What is wrong? Can i fix that?

UPD: HTML code for class head creation page:

<form accept-charset="UTF-8" action="http://0.0.0.0:3000/teacher_leaders" class="form-horizontal" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="ZKlDTKG8SU8fZuMrUfQoCOSGknOhj651DT2LJDrfliA=" /></div>
    <fieldset>

          <div class="control-group">
            <label class="control-label" for="user_teacher_leader_attributes_teacher_id">Teacher names</label>
            <div class="controls">

            <select id="teacher_id" name="teacher_id">
              <option value="1" selected="selected">Jack P. Tompson </option>
              <option value="2">Ronald V. Herwud</option>        
            </div>
          </div>

      <div class="control-group">
        <label class="control-label" for="user_user_login">Login</label>
        <div class="controls">
          <input id="user_user_login" name="user[user_login]" size="30" type="text" />
        </div>
      </div>

      <div class="control-group">
        <label class="control-label" for="user_password">Password</label>
        <div class="controls">
          <input id="user_password" name="user[password]" size="30" type="text" />
        </div>
      </div>  
</fieldset> 
    <input class="btn btn-large btn-success" name="commit" type="submit" value="Create" />
</form> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:19:19+00:00Added an answer on June 1, 2026 at 12:19 pm

    You need not

    <%= select_tag( :teacher_id, 
                            options_for_select( @teachers_collection, @choosen_teacher )) %>
    

    but something like

    <%= tl.select( :teacher_id, 
                            options_for_select( @teachers_collection, @choosen_teacher )) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a few Django models that look like this: class City(models.Model): name
I have few similar models in Django: class Material(models.Model): title = models.CharField(max_length=255) class Meta:
I have a few models which are not in the default cakephp format user(id,
I have a few models that need to have custom find conditions placed on
I have a few models: 'Article, Video, BlogPost, News, Commodity'. Each are in their
I have set up a few models in a simple django project. When I
I have quite a few libraries and models that get loaded into a controller,
Hi i am using django 1.2 .I my case i have few models which
I have a few models that contain static data, and I'm trying to cache
I have a few models I'm trying to relate. One model is Item ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.