OK again I got it:

  <%= button_to "Show", :controller => "watchedfamilies", :action =>
"create", :watchedfamily => {:Prio_No => "X5x5x5x5", :title =>
"Please", :watchedmembers_attributes => [{:Pub_No => "yyy1"}, {:Pub_No
=> "zzz2"}]} %>



On 27 Apr., 15:44, Sebastian <[email protected]> wrote:
> OK, I don't know why but it happens all the time that after posting a
> problem in a forum I am able to solve the problem, nearly!!!
>
> I think I was really on the wrong track!
>
> Now I added the following code in my patent view:
>
>   <%params = {:watchedfamily => {:Prio_No => "666666", :title =>
> "Please", :watchedmembers_attributes => [{:Pub_No => "Test1"},
> {:Pub_No => "Test2"}]}} %>
>   <%Watchedfamily.create!(params[:watchedfamily]) %>
>
> This is creating a new record with two nested records, exactlly what I
> wanted. Only problem is now: HOW TO FIRE THIS WITH ABUTTONOR LINK???
>
> Cheers
>
> On 27 Apr., 15:18, Sebastian <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I am working on a patentdatabase, where the user can first search the
> > patentdatabaseand thensavethe found patent with connected patents
> > (called familymembers). So I have a page called "patent" where the
> > search is done and all values that I need for thedatabaseare
> > available.
>
> > From that page I want to store the patent with his familymembers into
> > mydatabase, to watch them. So I have the following models
>
> > class Watchedfamily < ActiveRecord::Base
> >   has_many :watchedmembers
> >   accepts_nested_attributes_for :watchedmembers
> > end
>
> > class Watchedmember < ActiveRecord::Base
> >   belongs_to :watchedfamily
> > end
>
> > On my patent page I tried tosavethe data with a form that looks like
> > this (I had to define the controller that i want to use, because this
> > form is not in the watchedfamiles view!):
>
> > <% form_for :watchedfamily, :url => {:controller =>
> > "watchedfamilies", :action => "create" }  do |f| %>
> >     <%= f.text_field :Prio_No, :value => @prio_no %>
> >     <%= f.text_field :title, :value => @title %>
> >     <%= f.fields_for :watchedmembers_attributes do |x| %>
> >       <p>
> >       <%= x.text_field :Pub_No, :value => "Test" %>
> >       </p>
> >     <%end%>
> >     <p><%= submit_tag "Savehidden form" %></p>
> >   <% end %>
>
> > That is not working! Error is: "can't convert Symbol into Integer"
>
> > If I create the nested data directly in the watchedfamilies by
> > clicking new and using the form below it is working:
>
> > <%= form_for(@watchedfamily) do |f| %>
> >   <div class="field">
> >     <%= f.label :Prio_No %><br />
> >     <%= f.text_field :Prio_No %>
> >   </div>
> >   <div class="field">
> >     <%= f.label :title %><br />
> >     <%= f.text_field :title %>
> >   </div>
> >    <%= f.fields_for :watchedmembers do |x| %>
> >       <p>
> >       <%= x.text_field :Pub_No, :value => "Test" %>
> >       </p>
> >     <%end%>
> >   <div class="actions">
> >     <%= f.submit %>
> >   </div>
> > <% end %>
>
> > The problem is that my first approach is generating the following
> > request:
>
> > Parameters: {"watchedfamily"=>{"Prio_No"=>"123456",
> > "title"=>"Whatever", "watchedmembers_attributes"=>{"Pub_No"=>"Test"}},
> > "commit"=>"Create Watchedfamily"}
>
> > Where my second approach, directly from the watchedfamilies is
> > generating the following request:
>
> > Parameters: {"watchedfamily"=>{"Prio_No"=>"123456",
> > "title"=>"Whatever",
> > "watchedmembers_attributes"=>{"0"=>{"Pub_No"=>"Test"}}},
> > "commit"=>"Create Watchedfamily"}
>
> > First one watchedmembers_attributes is a string, second one is an
> > array.
>
> > If I change the line in my form from
> > <%= f.fields_for :watchedmembers_attributes do |x| %>
> > to
> > <%= f.fields_for :watchedmembers do |x| %>
>
> > I got the error: "Watchedmember(#26928120) expected, got
> > Array(#5756196)"
>
> > Maybe I am on a wrong track. I just want tosavea nested value
> > (patentfamily with its family members to mydatabase!)
> > I already watched tutorials and asked google, but I didn't find a
> > solution to my problem. I hope I get help here!!!
>
> > Cheers,
> > Sebastian

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to