他们有红宝石日期过滤器吗?

发布于 2024-12-09 17:49:31 字数 1280 浏览 1 评论 0原文

1) 我的人力资源管理应用程序中有一个请假申请表,我希望当用户输入“from_date”时,“to_date”应该大于“from_that”?

2) 在我的应用程序中,我有一个休假模型,用户可以在其中定义休假类型和允许的天数。在我的第二个模型中,leave_request 用户可以根据休假类型请求休假。一切正常。现在我想向用户显示可用的休假余额请假请求表单中允许的天数的基础?

迁移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

和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

如果用户没有足够的休假余额,我可以验证可用的休假数量吗?他们应该是一条消息,例如“您没有足够的休假来请求”等。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

孤独岁月 2024-12-16 17:49:31

你的第一个问题不太好理解。什么是“from_that”?如果您询问如何检查一个日期是在另一个日期之前还是之后,很简单:DateDateTime 包含 Comparable,以便您可以进行比较任意两个就像两个数字一样,例如:

>> DateTime.now > 1.day.ago
# => true

>> DateTime.now > Date.tomorrow
# => false

Your first question is not very comprehensible. What is "from_that"? If you're asking how to check if one date is before or after another, it's easy: Date and DateTime include Comparable so you can compare any two just like you would two numbers, e.g.:

>> DateTime.now > 1.day.ago
# => true

>> DateTime.now > Date.tomorrow
# => false
随心而道 2024-12-16 17:49:31

您可以编写自己的验证器,如下所示(未经测试的代码):

class LeaveRequest < ActiveRecord::Base
    validate :has_enough_leave

    def has_enough_leave
       if( to_date - from_date > employee.allowed_leave.days )
           errors.add(:to_date, "You do not have enough leave to requestt")
       end
    end

    ...

You can write your own validator, something like this (untested code):

class LeaveRequest < ActiveRecord::Base
    validate :has_enough_leave

    def has_enough_leave
       if( to_date - from_date > employee.allowed_leave.days )
           errors.add(:to_date, "You do not have enough leave to requestt")
       end
    end

    ...
孤独难免 2024-12-16 17:49:31

我通过以下方式完成了第一个问题:

class LeaveRequest < ActiveRecord::Base
      belongs_to :user
      belongs_to :leave

    validate :from_date_and_to_date

         def from_date_and_to_date
           if(to_date != from_date)
             errors.add(:to_date, " should be greater than from date" )
           end 
         end

I have done my first problem in following way:

class LeaveRequest < ActiveRecord::Base
      belongs_to :user
      belongs_to :leave

    validate :from_date_and_to_date

         def from_date_and_to_date
           if(to_date != from_date)
             errors.add(:to_date, " should be greater than from date" )
           end 
         end
萌梦深 2024-12-16 17:49:31

大家好,这里的朋友们,我对第二个问题有了新的答案

,我使用以下代码行来解决我的问题:

<label><a href="/leave_types">Leave Type</a></label>
  <label>Balance</label>

 <% for leave in @leave_types %> 
   <%= leave.leave_type %>
   <%= leave.allowed_leaves%>
 <% end %>

这在我的新的leave_request表单中显示了我的所有leave_types。

Hi friends here i came with a new answer of my second question

i used following line of code to fix my problem:

<label><a href="/leave_types">Leave Type</a></label>
  <label>Balance</label>

 <% for leave in @leave_types %> 
   <%= leave.leave_type %>
   <%= leave.allowed_leaves%>
 <% end %>

This displayed all my leave_types in my new leave_request form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文