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
New word
<%= error_messages_for :word, :definition %>
<% form_for(@word) do |f| %>
<%= f.label :word %>
<%= f.text_field :word %>
<%= f.label :was_created_by %>
<%= f.check_box :was_created_by %>
<% fields_for(:definition, @definition) do |i| %>
<%= i.label :definition %>
<%= i.text_area :definition %>
<%= i.label :word_type %>
<%= i.text_field :word_type %>
<%= i.label :pronounciation %>
<%= i.text_field :pronounciation %>
<%= i.label :origin %>
<%= i.text_area :origin %>
<%= i.label :is_profain %>
<%= i.check_box :is_profain %>
<% end %>
<%= submit_tag 'Create' %>
<% 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