My idea is to create a form along those lines:
<%= form_for(@timesheet, :html => {:multipart => true}) do |f| %>
<%= f.label "Date for timesheet" %>
<%= f.text_field :date %>
<!-- Add worked hours for each employee -->
<% @employee.each do |t| %>
<%= f.label t.fname %>
<br />
<%= f.label "Basic Hours" %>
<%= f.text_field :basic_hours %>
<%= f.label "Sunday/BH Hours" %>
<%= f.text_field :sunday_bh_hours %>
<br />
<% end %>
<%= f.submit 'Submit', :class => 'btn btn-primary' %>
<% end %>
On Tuesday, April 7, 2015 at 11:01:08 AM UTC+1, Colin Law wrote:
>
> On 7 April 2015 at 10:41, Bruno Walraven <[email protected]
> <javascript:>> wrote:
> > Hi all,
> >
> > I've been stuck trying to get a has_many :through relationship working
> on my
> > Rails application.
> >
> > I have a Employee model, a Timesheet model and a Payment model.
> > The Employee has many Timesheets and a Timesheet has many Employees.
> > The Timesheet table will contain its ID and a Date. the Payment model is
> the
> > join table, it belongs to a Employee and a Timesheet, it also has an
> extra
> > field called hours_worked.
> >
> > See below models
> >
> > class Timesheet < ActiveRecord::Base
> > belongs_to :user
> > has_many :payments
> > has_many :employees, :through => :payments
> > end
> >
> > class Employee < ActiveRecord::Base
> > belongs_to :user
> > has_many :payments
> > has_many :timesheets, :through => :payments
> > end
> >
> > class Payment < ActiveRecord::Base
> > belongs_to :employee
> > belongs_to :timesheet
> > end
> >
> >
> > I want to create a form where I can create a new Timesheet by chosing a
> > date, listing all Employees and allowing me to enter the hours_worked
> for
> > each employee.
> >
> > Once I submit the form, it should create a new Timesheet, and create a
> > Payment for each employee with each employee's hours_worked for that
> > specific Timesheet.
> >
> > I hope this makes sense and I can get your help!!
>
> So what is not working, or which bit don't you know how to do?
>
> Have you worked right through a good tutorial such as railstutorial.org?
>
> Colin
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/4b66ea0e-7d2e-47df-ac7f-6add488d44ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.