No one seems to be able to help with my request. I bet this can be done in rails, but I'm not going to figure it out without any help anytime soon.
Trying to be brief: I have three classes: Account, Employee, and AccountEmployeeRelation (which contains more than just the FKs).
In the form where I create a new account, I know how to add a ONE linked employee. I do not know how to extend this to add MULTIPLE linked employees.
Here is the working code for one employee:
def new
@account = Account.new
@relation = AccountEmployeeRelation.new
end
The View:
<% form_for :account, :url => { :action => :create } do |form| %>
Title: <%= form.text_field :title %><br/>
<% fields_for :relation do |f|%>
Employee: <%= f.select (:employee_id, Employee.find(:all).map{|u| [u.name, u.id]}) %><br/>
<% end %>
<%= submit_tag %>
<% end %>
Can anyone help with extending this? I think new needs to look like:
def new
@relations =
3.times do # I would not really do it this way.
@relations << AccountEmployeeRelation.new
end
end
And so on. However, I suspect in general you user interface is
too-closely matching the exact shape of your database. It should match
the way your users will typically enter their data.
I'm open to suggestons about my interface. If I wanted to make the
inerface easy (for me) I would make the user create an Account, and
then later go back and add assigned Employees. I think it will be
more convenient (but not for me) to be able to assign employees on the
same form that creates the account.
I'm open to suggestons about my interface. If I wanted to make the
inerface easy (for me) I would make the user create an Account, and
then later go back and add assigned Employees. I think it will be
more convenient (but not for me) to be able to assign employees on the
same form that creates the account.
The best deal there is show them a working interface as soon as
possible, with a few important features in it. Then they can request a
better look-and-feel, based on experience with the prototype...