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

  • Home
  • SEARCH
  • 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 9057667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:31:08+00:00 2026-06-16T14:31:08+00:00

Note : Before Answering the question understand this does not have to do anything

  • 0

Note : Before Answering the question understand this does not have to do anything with attr_accessible or attr_protected the RAILS is in question is 3.1.3 and Ruby 1.9.2p290

Without futher due Here my params that I try to mass assign to DriverLicense Model

 {"utf8"=>"✓",
 "authenticity_token"=>"cKhruPzVvBK63bqCQPFY8xPZb12V5lhLPOpXgjIToJk=",
 "driver_license"=>
  {"license_number"=>"LICENCE-001",
   "license_class"=>"A-CLASS",
   "validity_start_date"=>"02/01/2011",
   "validity_end_date"=>"08/24/2011",
   "issuing_authority"=>"RTO",
   "remarks"=>"Remarks .."},
 "save_button"=>"Save",
 "action"=>"create",
 "controller"=>"driver_licenses",
 "driver_id"=>"2"}

Here the controller code

@driver_license = @driver.driver_licenses.new(params[:driver_license])

Here the definition of model look like

class DriverLicense < ActiveRecord::Base
    acts_as_tenant(:tenant)
    validates :driver_id,:license_number,:validity_start_date,:validity_end_date,:presence => true  
    validate :date_validity ,:if => :is_date_present?

    validate :overlapping_validity,:if => :validity_start_date_present? 

    belongs_to :driver

    scope :active_licenses , where('validity_start_date <= ? and validity_end_date >= ?',Date.today,Date.today) 


    .... ....
    .... ....

    private
    def is_date_present?
        validity_start_date.present? and validity_end_date.present?
    end 


    def date_validity
      errors.add(:validity_start_date,"must be earlier then validity end date") if validity_start_date > validity_end_date
    end

    def validity_start_date_present?
        validity_start_date.present?
    end 


    def overlapping_validity
        arel =  self.class.where('validity_end_date >= ?',validity_start_date).where('driver_id = ?',driver_id)     
        arel = arel.where('id != ?',id) if id.present?      
        unless arel.count.zero?
            errors.add(:validity_start_date,"overLapping date with other licenses")
        end 
    end 

end

The mass-attributes work for all attributes except validity_end_date

#<DriverLicense id: nil, driver_id: 2, license_number: "LICENCE-001", license_class: "A-CLASS", issuing_authority: "RTO", validity_start_date: "2011-01-02", validity_end_date: nil, remarks: "Remarks ..", tenant_id: 2, created_at: nil, updated_at: nil>

Once can check that on screenshot as well further where the mass-assignment work for all attributes except validity_end_date

enter image description here

  • 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-16T14:31:09+00:00Added an answer on June 16, 2026 at 2:31 pm

    Found that the date format is not the same in the both the side
    & hence it setting it to nil

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

Sidebar

Related Questions

NOTE: Before reading this question please note that I have read the previous questions
Before answering, please note that this is a client side issue and not a
NOTE : Right before posting this question it occurred to me there's a better
Note this question was originally posted in 2009, before C++11 was ratified and before
Please note that this is not homework and i did search before starting this
Note, this is not a duplicate of .prop() vs .attr() ; that question refers
(Note: This is not a question about what is the best way with code
NOTE: This is a followup to my question here. I have a program that
Before starting, note that I have to update a website that is not mine,
Note : Before asking this question I did an exhaustive search, and found little

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.