ruby中update应该怎么写

Python019

ruby中update应该怎么写,第1张

Rails的?

假设表为people,类为Person

person = Person.find(params[:id])

person.update_attributes(name=params[:name],age=params[:age])

1.使用 text_field_tag :num controller里 取得中间表对应得那条(之后称为 xxx) update_attribute('num',params[:num])

2.使用 text_field :xxx, :num controller里 xxx.update_attributes(params[:xxx])

3.model中定义 accept_nest_attributes :xxx

view中 form里

<% f.field_for :xxx do |xxx| %>

<%= xxx.text_field :num %>

<% end %>