i am new to ruby on rails in my project i have two tables documents and
and in dependents there is a column called name and i want to populate
this column data in dropdown list and after selecting the name in the
dropdown list i want to store it in documents table column called
dependents_name for this what should be the controller and view.
(The form triggers the ‘update’ method, storing your @document.id in
params[:id]. The value that is selected by the user in the drop-down
box will be stored in params[:document][:dependent_id])
def update @document = Document.find(params[:id]) @document.update_attributes(params[:document])
# this line will update each attribute of @document with the
corresponding attribute in params[:document]. In this case, it’s the
same as if you did: @document.dependent_id =
params[:document][:dependent_id] and then @document.save.
This example stores the dependent_id rather than the dependant_name,
but that’s what you should store. Then in your Document model you
and in your Dependent model
Then you can view the name of the dependent for any document like this:
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.