3 models - User, Images, Interests. Everything looks ok but nothing
gets inserted into child models:(

Model code excerpt
**********************************
User model =>
has_many :interests, :as => :interestible, :dependent => :destroy
    accepts_nested_attributes_for :interests, :reject_if => proc {|
attributes| attributes["name"].blank?}

    has_many :images, :as => :imageible, :dependent => :destroy
    accepts_nested_attributes_for :images, :reject_if => proc {|
attributes| attributes["image_file_name"].blank?}

attr_accessible  :username, :password, :password_confirmation, :email, 
:images_attributes, :interests_attributes

*************************************

Controller Code
****************************************************
def new
        @user = User.new
        images = 2.tim...@user.images.build}
        interests = 3.tim...@user.interests.build}

        respond_to do |format|
            format.html # new.html.erb
            format.xml  { render :xml => @user }
        end
    end

View Code
************************************
<% semantic_form_for @user, :html => {:multipart => true} do |form| %>
  <%#= form.error_messages %>
  <% form.inputs do %>
    <%= form.input :username, :label => 'Username', :input_html =>
{:style => "width:50%"}%>
    <%= form.input :password, :label => 'Password' %>
    <%= form.input :password_confirmation, :label => 'Confirm
Password' %>
    <%= form.input :email, :label => 'Email' , :input_html => {:style
=> "width:50%"}%>
  <% end %>

  <%#images.each do |image| %>
    <% form.inputs :for=> :images,:name => 'Photo #%i' do |img|%>
      <%= img.input :image_description, :input_html => {:style =>
"width:50%"}%>
      <%= img.input :image %>
    <% end  %>
  <%# end  %>

  <%# interests.each do |interest| %>
    <% form.inputs :for=> :interests  do |inter|  %>
      <%= inter.input :interest_name, :input_html => {:style =>
"width:
50%"}%>
    <% end  %>
  <%# end  %>
  <%= form.buttons %>
<% end  %>
****************************
Log output

Processing UsersController#create (for 127.0.0.1 at 2010-02-26
15:31:15) [POST]
  Parameters:
{"user"=>{"images_attributes"=>{"0"=>{"image_description"=>"img1",
"image"=>#<File:C:/Users/amishra/AppData/Local/Temp/RackMultipart.
2972.0>}, "1"=>{"image_description"=>"i2", "image"=>#<File:C:/Users/
amishra/AppData/Local/Temp/RackMultipart.2972.1>}},
"interests_attributes"=>{"0"=>{"interest_name"=>"1"},
"1"=>{"interest_name"=>"1"}, "2"=>{"interest_name"=>"1"}},
"password_confirmation"=>"t", "username"=>"t7", "password"=>"t",
"email"=>"t...@t.com"}, "commit"=>"Create User",
"authenticity_token"=>"M3HPGt76KeSdL0D+038X4qATRi4sEDYRX/F2nxl23qU="}
   [4;36;1mSQL (1.0ms) [0m    [0;1mBEGIN [0m
   [4;35;1mUser Load (1.0ms) [0m    [0mSELECT `users`.id FROM `users`
WHERE (LOWER(`users`.`email`) = BINARY '....@t.com') LIMIT 1 [0m
   [4;36;1mUser Load (0.0ms) [0m    [0;1mSELECT `users`.id FROM
`users` WHERE (LOWER(`users`.`username`) = BINARY 't7') LIMIT 1 [0m
   [4;35;1mUser Load (0.0ms) [0m    [0mSELECT `users`.id FROM `users`
WHERE (`users`.`persistence_token` = BINARY
'61bd9e5355e137d2a83652d431c1870472b9e7bc63cca437e839ff8e80eaea5db5e3ec6d8ac56689dbcd5a49b9b0832c178fc6e1528967d31d66957b58867f0e')
LIMIT 1 [0m
   [4;36;1mUser Create (0.0ms) [0m    [0;1mINSERT INTO `users`
(`updated_at`, `last_request_at`, `crypted_password`,
`perishable_token`, `profile_photo_content_type`, `username`,
`password_salt`, `current_login_at`, `profile_photo_file_name`,
`failed_login_count`, `profile_photo_file_size`, `persistence_token`,
`login_count`, `profile_photo_updated_at`, `email`, `active`,
`created_at`) VALUES('2010-02-26 23:31:15', '2010-02-26 23:31:15',
'a5e0632538b78c7c886c1cb673575286e0dc1d6a2f59006282bf1af251c636bc95e6a827cd2156c1eb62fc19514d7724fec11e158ebb5faf0a88b77dd9a8c4cd',
'A9s-vLoDCsxLm8Q61b8v', NULL, 't7', 'Pe-oyjJ9sQr4L9ZyApSb',
'2010-02-26 23:31:15', NULL, 0, NULL,
'61bd9e5355e137d2a83652d431c1870472b9e7bc63cca437e839ff8e80eaea5db5e3ec6d8ac56689dbcd5a49b9b0832c178fc6e1528967d31d66957b58867f0e',
1, NULL, '....@t.com', 1, '2010-02-26 23:31:15') [0m
Sent mail to t...@t.com
******************************************

-- 
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 rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to