开发者

How would a form_for a Timesheet application work in Rails

I have the following ActiveRecord models

class User < ActiveRecord::Base
  has_many :timesheets
end

class Timesheet < ActiveRecord::Base
  belongs_to :user
  has_many :work_days
end

class WorkDay < ActiveRecord::Base
  belongs_to :timesheet
end

The WorkDay model has attributes like hours, days, comments, etc.

I can not figure out how the form would look like in rails for this.. I saw some complex forms from railscasts but still not getting it.

I am envisioning a form like below (for 7 days):

06/19 (Day1)  06/20 (Day2)  06/21 (Day3)  ...  06/26 (Day 7)
textfield 1   textfield 2   textfield 3   ...  开发者_运维问答textfield4

<submit>

So I have 7 textfields in this form (might have comments for each one as well).

Can someone tell me/explain me how the form_for would look for this.


You will be having something like this -

<%= form_for @timesheet do |f| %>

 # Fields for @timesheet attributes.     
 <% f.fields_for 7.times.map{@timesheet.workd_day.new}.each do |t| %>
   Hour: <%= t.text_field hour %>
   Days: <%= t.text_field days %>
   Comments: #one more fields for block for comments.
 <% end %>

 <%= f.sumit "Save" %>
<% end %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜