ruby on rails - Join two tables and select record(table2) to form(table1) with drop-down-select -


i join 2 tables have table 'persons' , table 'factories'.

my question is, how can add person , choose (with dropdown) factory person belongs to?

my persons model:

class person < activerecord::base   has_many :factories    has_attached_file :cv    attr_accessible :cv, :email, :function, :mobile, :telephone end 

my factories model:

class factory < activerecord::base     belongs_to :persons    attr_accessible :last_name, :email, :telephone, :first_name, :website, :country end 

i want example:


| add person |

function: (input field)

telephone: (input field)

mobile: (input field)

email: (input field)

factory (drop-down) <= actual field have , not placed in persons table default.

cv: (upload field)

submit: (submit button)


i hope understand have , hope help.


**edit 1 changed plans. have chosen factory.id in column in persons table.

i made column in person table name factory.id to store data other table in column. possible?**

you can this:

controller:

@people=person.new  @factories = factory.all 

view:

    form_for @people |a| . . .     = a.select :factory, options_for_select(@factories.map{ |f| [f.name, f.id] }) 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -