1
在我的Rails3中的應用我有兩個控制器葉leave_request和相應的models.Their遷移是:在其他模型視圖中顯示一個模型數據?
葉表:
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_requests表:
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 :leave_balance
t.integer :user_id
t.integer :company_id
t.timestamps
end
end
def self.down
drop_table :leave_requests
end
end
,並考慮:
<!-- Right column/section -->
<aside class="column width2" >
<p ><a href="/leave_requests" class="btn btn-special btn-green"><img SRC="images/add.png" class="icon" alt=""/>View All Requests </a></p>
<div class = "zebra-sriped">
<table width="300">
<tr>
<th colspan="1">Leave</th>
<th colspan="1">Balance</th>
</tr>
<tbody>
<tr>
<th><%= Leave.find(@leave.leave_type).leave_type %>></th>
<th> <%= Leave.find(@leave.leave_type).allowed_leaves %></th>
</tr>
</tbody>
</table>
</div>
</aside>
<!-- End of Right column/section -->
我創建了幾個lea ve類型例如:年度,休假,付費,未付等etc. allowed_leaves的數量也手動保存。現在我想在用戶創建請假時顯示leave_types(只讀)和allowed_leaves(只讀)的數量,並且在最後驗證允許的假期,即用戶不能請求超過允許的假期。 在此先感謝
嗨,魯珀特再次感謝。但是這並沒有解決我的查詢問題。我只想在leave_request表單中顯示leave_types和相對允許的一天離開模型。 – Ravindra