1)
i have a leave request form in my HRM application, i want that when a user enter the “from_date”, the “to_date” should be greater than “from_that”?
2)
In my app i have a leave model in which user can defined leave type and day’s allowed.In my second model leave_request user can request for leave according to leave type.Everything is working well.Now i want to display leave balance available to user on basis of allowed day’s in leave_request form?
Migration leave.rb:
class CreateLeaves < ActiveRecord::Migration
def self.up
create_table :leaves do |t|
t.integer :user_id
t.integer :company_id
t.string :leave_type
t.integer :allowed_leaves
t.text :description, :limit => 500
t.timestamps
end
end
def self.down
drop_table :leaves
end
end
And leave_request.rb:
class CreateLeaveRequests < ActiveRecord::Migration
def self.up
create_table :leave_requests do |t|
t.integer :employee_id
t.integer :leave_type
t.date :from_date
t.date :to_date
t.text :reason_for_leave
t.string :contact_during_leave, :limit => 10
t.integer :user_id
t.integer :company_id
t.timestamps
end
end
def self.down
drop_table :leave_requests
end
end
And can i validate number of leaves available like if user do not have enough leave balance than their should be a message like”You do not have enough leave to request ” etc.
Hi friends here i came with a new answer of my second question
i used following line of code to fix my problem:
This displayed all my leave_types in my new leave_request form.