私はレールの完全な初心者ですが、独学で教えており、簡単な問題を自分で解決できるようです。しかし、現時点では解決できない問題があります。フォームのすべてのフィールドに入力した後、「新規」または「作成」アクションを呼び出して新しいレコードを作成すると、空白のレコードがデータベースにコミットされます。すべてのフィールドが「null」です。
INSERT INTO `clients` (`accountholder`, `allergies`, `birthdate`, `cell`, `created_at`, `data1`, `data2`, `data3`, `data4`, `emailaddress`, `fax`, `middlename`, `name`, `surname`, `tel`, `text`, `updated_at`) VALUES (NULL, NULL, NULL, NULL, '2012-08-20 09:10:46', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2012-08-20 09:10:46')
@post = Client.update_attributes(params[:id]) are correctのコンソールでのログダンプ中にデータを確認できます。
client_controller.rb
def new
@post = Client.create
end
def create
@post = Client.new(params[:posts])
if @post.save
redirect_to clients_path
else
render "new"
end
end
index.html.erb
<%= form_for @post do |x| %>
<p>
<%= x.label :name %><br />
<%= x.text_field :name, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.label :surname %>
<%= x.text_area :surname, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.label :middlename %>
<%= x.text_area :middlename, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.label :tel %>
<%= x.text_area :tel, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.label :cell %>
<%= x.text_area :cell, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.label :allergies %>
<%= x.text_area :allergies, :cols => "30", :rows => "10" %>
</p>
<p>
<%= x.label :fax %>
<%= x.text_area :fax, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.label :birthdate %>
<%= x.text_area :birthdate, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.submit "Add a New Client" %>
</p>
<% end %>
アドバイスをいただければ幸いです。