Hello everybody.
I’m trying to make the save and update 2 tables and I can not do the same. Use Ruby 4 Rails 2.
Table I and Table cases valves. Need to save four valves in each case.
Now I can list both on the same view of the cordon with the codes below:
Model Caso
class Caso < ActiveRecord::Base
attr_accessible :name
has_many :valva, :dependent => :destroy, :autosave => true
accepts_nested_attributes_for :valva
end
``
Model valva
class Valva < ActiveRecord::Base
attr_accessible :caso_id, :valva_tipo
belongs_to :caso
end
``
Routes
resources :casos do
resources :valvas
end
``
casos_controller.rb
def new
@caso = Caso.new
4.times do
@caso.valva.build
end
end
``
_form.html.erb de Caso
<%= form_for(@caso) do |f| %>
...
<%= f.label :name %><br>
<%= f.text_field :name %>
<%= f.fields_for :valva do |v| %>
<div class="field">
<%= v.label :valva_tipo %>
<%= v.number_field :valva_tipo %>
</div>
<% end %>
<%= f.submit %>
<% end %>
``