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| %>

          ...

   <div class="field">
     <%= f.label :name %><br>
     <%= f.text_field :name %>
   </div>

   <%= f.fields_for :valva do |v| %>
      <div class="field">
               <%= v.label :valva_tipo %>
        <%= v.number_field :valva_tipo %>
      </div>
   <% end %>

   <div class="actions">
     <%= f.submit %>
   </div>
<% end %>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/77bf3580-a0f7-4c84-8e6f-8c96216eb98f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Luis Bivar Ramos at Oct 16, 2013 at 4:38 pm
    Hi,

    Can you post the error you're getting and the log?


    Thanks

    On Wednesday, October 16, 2013 11:44:18 AM UTC+1, Gilvam wrote:

    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| %>

    ...

    <div class="field">
    <%= f.label :name %><br>
    <%= f.text_field :name %>
    </div>

    <%= f.fields_for :valva do |v| %>
    <div class="field">
    <%= v.label :valva_tipo %>
    <%= v.number_field :valva_tipo %>
    </div>
    <% end %>

    <div class="actions">
    <%= f.submit %>
    </div>
    <% end %>
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/eadf1d97-05a1-4b52-a6b2-8b4a156e031f%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Frederick Cheung at Oct 16, 2013 at 4:52 pm

    On Wednesday, October 16, 2013 11:44:18 AM UTC+1, Gilvam wrote:
    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


    You need to mark :valva_attributes as accessible too or Active Record
    won't let it through. If that doesn't fix things, could you give more
    details as to how it's not working?

    Fred

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f7b8e5d2-03a2-4a45-a320-5c57aa37dfed%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 16, '13 at 12:49p
activeOct 16, '13 at 4:52p
posts3
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase