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 9014663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:33:38+00:00 2026-06-16T03:33:38+00:00

i have two models department and address and they are associated with one another

  • 0
  1. i have two models department and address and they are associated
    with one another but when i use client side form validation address
    model fields are not getting validated. The javascript for
    validating associated model is not being generated.
  2. Department model

    class Department < ActiveRecord::Base   
        attr_accessible :agency_head, :agency_head_rank, :department_type_id, :fax, :name,
                        :phone, :address_attributes
        validates :name , :length => { :minimum => 2 } , :presence => true
        validates :department_type_id , :agency_head,:agency_head_rank,:phone,:fax, :presence => true
    
        belongs_to :department_type
        belongs_to :address, :class_name => "Address", :foreign_key => "address_id"   
        accepts_nested_attributes_for :address,:allow_destroy => true
    end
    
  3. Address model

    class Address < ActiveRecord::Base   
        attr_accessible :state, :street1, :street2, :town, :zipcode, :county   
        validate :street1 ,:street2,:town,:state,:county,:zipcode ,:presence => true   
        has_one :department  
    end
    
  4. view-page

            <h1 id="form-title">Add New Department</h1>
    
            <%=form_for @department ,:validate=>true do |f|%>   
    <div    id="respond">
                <% if @department.errors.any? %>
                <div id="error_explanation">
                    <h2><%= pluralize(@department.errors.count, "error") %> prohibited this post from being saved:</h2>
    
                    <ul>
                        <% @department.errors.full_messages.each do |msg| %>
                        <li>
                            <%= msg %>
                        </li>
                        <% end %>
                    </ul>
                </div>
                <% end %>
    
                <p class="comment-form-author">
                    <label for="Department Name">Department&nbsp;Name</label><span class="required">*</span>
                    <%= f.text_field :name, :size => 30, 'aria-required' => 'true'  %>
                </p>
                <p class="comment-form-author">
                    <label for="Department Type">Department&nbsp;Type</label>
                    <%= f.collection_select :department_type_id, @dept_types, :id, :name, :prompt => true %>
                </p>
    
                <%= f.fields_for :address, @department.address ,:validate=> true do |addr| %>
                <p class="comment-form-author">
                    <label for="Street1">Street 1</label>
                    <%= addr.text_field :street1 , :size => 30, 'aria-required' => 'true'  %>
                </p>
                <p class="comment-form-author">
                    <label for="Street 2">Street 2</label>
                    <%= addr.text_field :street2, :size => 30, 'aria-required' => 'true'  %>
                </p>
                <p class="comment-form-author">
                    <label for="Town">Town</label>
                    <%= addr.text_field :town, :size => 30, 'aria-required' => 'true'  %>
                </p>
    
                <p class="comment-form-author">
                    <label for="State">State</label>
                    <%= addr.text_field :state, :size => 30, 'aria-required' => 'true'  %>
                </p>
                <p class="comment-form-author">
                    <label for="State">County</label>
                    <%= addr.text_field :county, :size => 30, 'aria-required' => 'true'  %>
                </p>
    
                <p class="comment-form-author">
                    <label for="Zip Code">Zip Code</label>
                    <%= addr.text_field :zipcode, :size => 30, 'aria-required' => 'true'  %>
                </p>
    
                <% end %>
    
                <p class="comment-form-author">
                    <label for="agency head">Agency Head</label><span class="required">*</span>
                    <%= f.text_field :agency_head, :size => 30, 'aria-required' => 'true'  %>
                </p>
                <p class="comment-form-author">
                    <label for="agency head rank">Agency Head Rank</label><span class="required">*</span>
                    <%= f.text_field :agency_head_rank, :size => 30, 'aria-required' => 'true'  %>
                </p>
    
                <p class="comment-form-author">
                    <label for="phone">Phone</label><span class="required">*</span>
                    <%= f.text_field :phone, :size => 30, 'aria-required' => 'true'  %>
                </p>
                <p class="comment-form-author">
                    <label for="fax">Fax</label><span class="required">*</span>
                    <%= f.text_field :fax, :size => 30, 'aria-required' => 'true'  %>
                </p>
                            </div>
                        <div class="spacer">
                <br/>
                <center>
                    <%= f.button " Submit ", :id => 'my_login_form_button' %>
                </center>           </div>          <% end %>       </div> </div>   </div> </div> </div>
    
  • 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-16T03:33:40+00:00Added an answer on June 16, 2026 at 3:33 am

    I find out my mistake use this one in address model.

    validates :street1 ,:street2,:town,:state,:county,:zipcode ,:presence => true

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two associated models (meetings and departments). A meeting has exactly one department,
I have two models, Listing and Invitation, associated with has_and_belongs_to_many. I am looking at
I have two models, A and B, and one light, L. I would like
I have two models, one is Group, the other Item. A group has many
I have two dropdown in a form for selecting department and designation. $model =
I have two models, one called Notes and one called Comments. Comments can be
I have two models in cakePHP, one is Parts and the other is Orders
I have two models: Client and Invoice. Every client can have many invoices, every
I have two models class Subscription < ActiveRecord::Base belongs_to :client end class Client <
I have two models in relation one-to-many: class Question(db.Model): questionText = db.StringProperty(multiline=False) class Answer(db.Model):

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.