views:

12

answers:

0

Hi everybody,
I would like to know which way is the best to resolve my question :
I have a form in order to select people via a select field. If the name is missing in the select field, a text field is available to add directly the person's name.
- The form in new.html.erb is the format of the new action of the Team controller.
- The list of the people is extracted from the People model.

def new
@team = Team.new
@people = People.all
end

I created an attribute in the Team model to store the new_person text field :

class Team < ActiveRecord::Base
attr_accessor :new_person
...
end

Finally, here's an extract of my view :

<%= f.select :person_id, @people.map { |p| [p.name, p.id] } %>
<%= f.text_field :new_person %>

Obviously, I would like to save the new person in the table Person before saving the data from the form. As usual, the id are saved instead of the names

At this point, I've got two issues :
1/ The params array has the key new_person what doesn't have the table. So it is not possible to use the Team.new(params[:team]) method. Does exist an easy solution to avoid this problem ? 2/ As I need the person_id, how can I get it when the name comes from the new_person field? In using the before_filter method ?

Thanks a lot,
Camille.