Thanks everyone for your suggestions. This is what I came up with I was looking for some feedback. It works fine but I figure I might be doing something long winded. This is my first go at an actual railsApp other then book demos. Any feedback would be nice!
// new.html.erb <h1>New word</h1> <%= error_messages_for :word, :definition %> <% form_for(@word) do |f| %> <p> <%= f.label :word %><br /> <%= f.text_field :word %> </p> <p> <%= f.label :was_created_by %><br /> <%= f.check_box :was_created_by %> </p> <% fields_for(:definition, @definition) do |i| %> <p> <%= i.label :definition %><br /> <%= i.text_area :definition %> </p> <p> <%= i.label :word_type %><br /> <%= i.text_field :word_type %> </p> <p> <%= i.label :pronounciation %><br /> <%= i.text_field :pronounciation %> </p> <p> <%= i.label :origin %><br /> <%= i.text_area :origin %> </p> <p> <%= i.label :is_profain %><br /> <%= i.check_box :is_profain %> </p> <% end %> <p> <%= submit_tag 'Create' %> </p> <% end %> <%= link_to 'Back', words_path %> // words_controller.rb def create @client_ip = request.remote_ip begin ActiveRecord::Base.transaction do @word = Word.new(params[:word].merge(:ip_address => @client_ip, :user_id => '1')) @word.save @definition = Definition.new(params[:definition].merge (:ip_address => @client_ip, :user_id => '1', :word_id => @word.id, :status => 'published')) @definition.save end rescue ActiveRecord::RecordInvalid => invalid flash[:notice] = 'Word was not created' render :action => "new" end redirect_to(@word) end On Aug 29, 4:16 am, Sijo Kg <rails-mailing-l...@andreas-s.net> wrote: > Hi brianp > From what I understood you have to put the whole thing in a > transaction like > > ActiveRecord::Base.transaction do > save first model object > save second model object > end > > Sijo > -- > Posted viahttp://www.ruby-forum.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-talk@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 -~----------~----~----~----~------~----~------~--~---