既存のすべてのスタブリッシュメントを含むインデックス ページを作成しようとしています。クリックすると、新しいスタブリッシュメントを作成するためのフォームが表示されるようなリンク。
Controller:
def index
@stablishments = Stablishment.all
@new_stablishment = Stablishment.new()
end
def create
@stablishment = Stablishment.new
@stablishment.update_attributes(params[:stablishment])
end
Index:
Index
<div id="create_stablishment">
<%= link_to "Crear Nuevo Establecimiento", '#' %>
</div>
<div id="stablishment_form_fields" style="display:none;">
<%= form_for(@new_stablishment, :remote => true) do |f| %>
<%= render :partial => 'stablishments/form_fields', :locals => {f: f} %>
<% end %>
</div>
<div id="stablishments_list">
<% @stablishments.each_with_index do |stablishment, i| %>
<%= render stablishment, :count => i %>
<% end %>
</div>
<div id="mensaje"></div>
form_fields:
<div class="form_fields">
<%= f.label "Nombre" %>
<%= f.text_field :name %>
</div>
<div class="form_fields">
<%= f.label "Ciudad" %>
<%= f.text_field :city %>
</div>
<div class="form_fields">
<%= f.label "Estado" %>
<%= f.text_field :state %>
</div>
<div class="form_fields">
<%= f.label "Direccion" %>
<%= f.text_field :address %>
</div>
<div class="form_fields">
<%= f.label "Email" %>
<%= f.text_field :mail %>
</div>
<div class="form_fields">
<%= f.label "Sitio Web" %>
<%= f.text_field :web_site %>
</div>
<div class="form_fields">
<%= f.label "Tipo" %>
<%= f.text_field :stablishment_type %>
</div>
<div class="form_fields">
<%= f.submit %>
</div>
create.js:
$("#stablishment_form_fields").hide();
$("#mensaje").html("se ha creado");
スタブリッシュメントの作成をクリックすると、オブジェクトが作成されます。ログ:
Started POST "/stablishments" for 127.0.0.1 at 2012-09-15 20:47:05 -0300
Processing by StablishmentsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"VDf47PuVfNH7UPLEyVqtY4n+2DgmCKT3Jvx2wljMtZY=", "stablishment"=>{"name"=>"6", "city"=>"", "state"=>"", "address"=>"", "mail"=>"", "web_site"=>"", "stablishment_type"=>""}, "commit"=>"Create Stablishment"}
(0.2ms) BEGIN
SQL (0.4ms) INSERT INTO `stablishments` (`address`, `city`, `created_at`, `mail`, `name`, `phone`, `stablishment_type`, `state`, `updated_at`, `web_site`) VALUES ('', NULL, '2012-09-15 23:47:05', '', '6', NULL, NULL, NULL, '2012-09-15 23:47:05', '')
(119.6ms) COMMIT
Rendered stablishments/create.js.erb (0.8ms)
Completed 200 OK in 176ms (Views: 7.4ms | ActiveRecord: 120.2ms)
Started POST "/stablishments" for 127.0.0.1 at 2012-09-15 20:47:05 -0300
Processing by StablishmentsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"VDf47PuVfNH7UPLEyVqtY4n+2DgmCKT3Jvx2wljMtZY=", "stablishment"=>{"name"=>"6", "city"=>"", "state"=>"", "address"=>"", "mail"=>"", "web_site"=>"", "stablishment_type"=>""}, "commit"=>"Create Stablishment"}
(1.0ms) BEGIN
SQL (0.4ms) INSERT INTO `stablishments` (`address`, `city`, `created_at`, `mail`, `name`, `phone`, `stablishment_type`, `state`, `updated_at`, `web_site`) VALUES ('', NULL, '2012-09-15 23:47:05', '', '6', NULL, NULL, NULL, '2012-09-15 23:47:05', '')
(58.9ms) COMMIT
Rendered stablishments/create.js.erb (0.1ms)
Completed 200 OK in 76ms (Views: 10.3ms | ActiveRecord: 60.3ms)
なぜこれが起こっているのでしょうか?