У меня есть форма, где я не знаю, сколько текстовых полей будет. Для каждой строки в таблице/форме есть базовое имя файла и скрытое поле рядом с ним, поэтому оно передается вместе с 2 текстовыми полями params[:lots[key][lot_number][:low_range][:high_range]
.Rails Losing Params во время метода почты
Как только я доберусь до контроллера, у меня есть только 2 - 3 из исходных 8 наборов полей, которые были созданы. Я не уверен, почему эти другие поля остались позади.
Я пробовал делать это с полями 15+, и он все равно получает только 5-7 лотов каждый раз.
Информация, которую я получаю, верна и правильно сформирована. Я просто всегда не хватает более половины лотов, которые отображаются в @video_filenames
петле
Вид:
<%= form_tag mass_create_from_media_admin_event_lots_path(@event), :method => :post do %>
<table class='list'>
<th>Lots</th>
<th>Sub Lot Creation</th>
<% if !params[:videos] || params[:videos] == '1' %>
<% @video_filenames.reject(&:blank?).uniq.each do |filename| %>
<% basename = File.basename(filename, '.*') %>
<% unique_key = Time.now.to_f %>
<tr>
<td><%= basename %><%= hidden_field_tag "lots[#{unique_key}][lot_number]", basename %></td>
<td><%= text_field_tag "lots[#{unique_key}][low_range]" %> <%= text_field_tag "lots[#{unique_key}][high_range]" %></td>
</tr>
<% end %>
<% end %>
</table>
<%= submit_tag "Create Lots" %>
<% end %>
Контроллер:
def mass_create_from_media
@event = Event.find(params[:event_id])
lots = params[:lots]
abort(params.to_s)
errors = []
lots.each do |key , lot|
if @event.lots.where(:number => lot[:lot_number]).empty?
new_lot = @event.lots.new(:number => lot[:lot_number], :start_at => Time.now, :end_at => Time.now + 1.hour)
if !new_lot.save
errors << new_lot.errors.full_messages
else
if lot[:low_range].present? && lot[:high_range].present?
index = lot[:low_range]
while lot[:high_range].to_i >= index.to_i
sub_lot = @event.lots.new(:number => lot[:lot_number] + '-' + index.to_s, :start_at => Time.now, :end_at => Time.now + 1.hour)
index = index.to_i + 1
sub_lot.save
end
end
end
end
end
if errors.present?
flash[:error] = "Errors creating lots: #{errors.join(', ')}"
else
flash[:success] = "Lots successfully created"
end
redirect_to mass_new_admin_event_lots_path(@event)
end
Сервер Выход:
Started POST "/admin/events/18342/lots/mass_create_from_media" for 127.0.0.1 at 2013-05-24 11:02:56 -0600
[1m[35mSQL (0.0ms)[0m SELECT DISTINCT `domains`.id FROM `domains` LEFT OUTER JOIN `content_options` ON `content_options`.`contentable_id` = `domains`.`id` AND `content_options`.`contentable_type` = 'Domain' LEFT OUTER JOIN `companies` ON `companies`.`id` = `domains`.`company_id` LEFT OUTER JOIN `content_options` `content_options_companies` ON `content_options_companies`.`contentable_id` = `companies`.`id` AND `content_options_companies`.`contentable_type` = 'Company' WHERE `domains`.`name` = 'dvauction.com' LIMIT 1
[1m[36mSQL (0.0ms)[0m [1mSELECT `domains`.`id` AS t0_r0, `domains`.`company_id` AS t0_r1, `domains`.`name` AS t0_r2, `domains`.`title` AS t0_r3, `domains`.`contact` AS t0_r4, `domains`.`latitude` AS t0_r5, `domains`.`longitude` AS t0_r6, `domains`.`meta` AS t0_r7, `domains`.`street_1` AS t0_r8, `domains`.`street_2` AS t0_r9, `domains`.`city` AS t0_r10, `domains`.`state` AS t0_r11, `domains`.`zip` AS t0_r12, `domains`.`country` AS t0_r13, `domains`.`phone_1` AS t0_r14, `domains`.`phone_2` AS t0_r15, `domains`.`phone_3` AS t0_r16, `domains`.`fax` AS t0_r17, `domains`.`email` AS t0_r18, `domains`.`url` AS t0_r19, `domains`.`legacy_id` AS t0_r20, `domains`.`require_banking_from_user` AS t0_r21, `domains`.`analytics` AS t0_r22, `domains`.`redirect_back_to_dvauction` AS t0_r23, `domains`.`created_at` AS t0_r24, `domains`.`updated_at` AS t0_r25, `content_options`.`id` AS t1_r0, `content_options`.`contentable_id` AS t1_r1, `content_options`.`contentable_type` AS t1_r2, `content_options`.`key` AS t1_r3, `content_options`.`content` AS t1_r4, `content_options`.`created_at` AS t1_r5, `content_options`.`updated_at` AS t1_r6, `companies`.`id` AS t2_r0, `companies`.`name` AS t2_r1, `companies`.`domain_name` AS t2_r2, `companies`.`use_amazon_ses` AS t2_r3, `companies`.`created_at` AS t2_r4, `companies`.`updated_at` AS t2_r5, `content_options_companies`.`id` AS t3_r0, `content_options_companies`.`contentable_id` AS t3_r1, `content_options_companies`.`contentable_type` AS t3_r2, `content_options_companies`.`key` AS t3_r3, `content_options_companies`.`content` AS t3_r4, `content_options_companies`.`created_at` AS t3_r5, `content_options_companies`.`updated_at` AS t3_r6 FROM `domains` LEFT OUTER JOIN `content_options` ON `content_options`.`contentable_id` = `domains`.`id` AND `content_options`.`contentable_type` = 'Domain' LEFT OUTER JOIN `companies` ON `companies`.`id` = `domains`.`company_id` LEFT OUTER JOIN `content_options` `content_options_companies` ON `content_options_companies`.`contentable_id` = `companies`.`id` AND `content_options_companies`.`contentable_type` = 'Company' WHERE `domains`.`name` = 'dvauction.com' AND `domains`.`id` IN (6)[0m
Processing by Admin::LotsController#mass_create_from_media as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ZyXjRKnFq/bTY0JDrIiIK18ko+rNGunl0RzP4KPU0m8=", "lots"=>{"1369414974.510821"=>{"lot_number"=>"20z", "low_range"=>"", "high_range"=>""}, "1369414974.511821"=>{"lot_number"=>"rock_on", "low_range"=>"", "high_range"=>""}}, "commit"=>"Create Lots", "event_id"=>"18342"}
[1m[35mUser Load (0.0ms)[0m SELECT `users`.* FROM `users` WHERE `users`.`company_id` = 2 AND `users`.`id` = 140742 LIMIT 1
[1m[36mPermission Load (0.0ms)[0m [1mSELECT `permissions`.* FROM `permissions` WHERE `permissions`.`user_id` IN (140742) ORDER BY priority ASC, subject_id ASC[0m
[1m[35mEvent Load (1.0ms)[0m SELECT `events`.* FROM `events` WHERE `events`.`id` = 18342 LIMIT 1
[1m[36m (1.0ms)[0m [1mSELECT COUNT(*) FROM `lots` WHERE `lots`.`event_id` = 18342 AND `lots`.`number` = '20z'[0m
[1m[35m (0.0ms)[0m BEGIN
[1m[36mSQL (1.0ms)[0m [1mINSERT INTO `lots` (`approved`, `base_price`, `bid_history`, `buy_now_price`, `comments`, `created_at`, `description`, `display_type`, `end_at`, `event_id`, `extension_time_in_minutes`, `featured`, `group`, `legacy_id`, `minimum_bid_increment`, `notes`, `notify_when_outbid`, `number`, `position`, `price`, `quantity`, `reserve_price`, `show_current_bid`, `show_price_post_sale`, `start_at`, `status`, `title`, `units`, `updated_at`) VALUES (0, 0.01, 'Do not show', NULL, NULL, '2013-05-24 17:02:56', NULL, 'Live', '2013-05-24 18:02:56', 18342, 0, 0, NULL, NULL, 0.01, NULL, 1, '20z', NULL, NULL, NULL, NULL, 1, 1, '2013-05-24 17:02:56', 'Preview', NULL, NULL, '2013-05-24 17:02:56')[0m
[1m[35mImage Load (3.0ms)[0m SELECT `images`.* FROM `images` JOIN image_containers ON image_containers.image_id = images.id LEFT JOIN lots ON lots.id = image_containers.imageable_id AND imageable_type = 'Lot' WHERE ((image_containers.imageable_type = 'Event' AND image_containers.imageable_id = 18342) OR (image_containers.imageable_type = 'Lot' AND lots.event_id = 18342)) AND (image_file_name REGEXP '^20z(-.*)*([[:space:]](.*))*.(gif|png|jpg|jpeg)') GROUP BY image_id ORDER BY image_file_name
[1m[36mVideo Load (2.0ms)[0m [1mSELECT `videos`.* FROM `videos` JOIN video_containers ON video_containers.video_id = videos.id LEFT JOIN lots ON lots.id = video_containers.videoable_id AND videoable_type = 'Lot' WHERE ((video_containers.videoable_type = 'Event' AND video_containers.videoable_id = 18342) OR (video_containers.videoable_type = 'Lot' AND lots.event_id = 18342)) AND (video_file_name REGEXP '^20z(-.*)*([[:space:]](.*))*.(flv|f4v)') GROUP BY video_id ORDER BY video_file_name[0m
[1m[35mSQL (1.0ms)[0m INSERT INTO `video_containers` (`video_id`, `videoable_id`, `videoable_type`) VALUES (13, 436036, 'Lot')
[1m[36m (1.0ms)[0m [1mCOMMIT[0m
[1m[35m (0.0ms)[0m SELECT COUNT(*) FROM `lots` WHERE `lots`.`event_id` = 18342 AND `lots`.`number` = 'rock_on'
[1m[36m (1.0ms)[0m [1mBEGIN[0m
[1m[35mSQL (1.0ms)[0m INSERT INTO `lots` (`approved`, `base_price`, `bid_history`, `buy_now_price`, `comments`, `created_at`, `description`, `display_type`, `end_at`, `event_id`, `extension_time_in_minutes`, `featured`, `group`, `legacy_id`, `minimum_bid_increment`, `notes`, `notify_when_outbid`, `number`, `position`, `price`, `quantity`, `reserve_price`, `show_current_bid`, `show_price_post_sale`, `start_at`, `status`, `title`, `units`, `updated_at`) VALUES (0, 0.01, 'Do not show', NULL, NULL, '2013-05-24 17:02:56', NULL, 'Live', '2013-05-24 18:02:56', 18342, 0, 0, NULL, NULL, 0.01, NULL, 1, 'rock_on', NULL, NULL, NULL, NULL, 1, 1, '2013-05-24 17:02:56', 'Preview', NULL, NULL, '2013-05-24 17:02:56')
[1m[36mImage Load (3.0ms)[0m [1mSELECT `images`.* FROM `images` JOIN image_containers ON image_containers.image_id = images.id LEFT JOIN lots ON lots.id = image_containers.imageable_id AND imageable_type = 'Lot' WHERE ((image_containers.imageable_type = 'Event' AND image_containers.imageable_id = 18342) OR (image_containers.imageable_type = 'Lot' AND lots.event_id = 18342)) AND (image_file_name REGEXP '^rock_on(-.*)*([[:space:]](.*))*.(gif|png|jpg|jpeg)') GROUP BY image_id ORDER BY image_file_name[0m
[1m[35mVideo Load (2.0ms)[0m SELECT `videos`.* FROM `videos` JOIN video_containers ON video_containers.video_id = videos.id LEFT JOIN lots ON lots.id = video_containers.videoable_id AND videoable_type = 'Lot' WHERE ((video_containers.videoable_type = 'Event' AND video_containers.videoable_id = 18342) OR (video_containers.videoable_type = 'Lot' AND lots.event_id = 18342)) AND (video_file_name REGEXP '^rock_on(-.*)*([[:space:]](.*))*.(flv|f4v)') GROUP BY video_id ORDER BY video_file_name
[1m[36mSQL (1.0ms)[0m [1mINSERT INTO `video_containers` (`video_id`, `videoable_id`, `videoable_type`) VALUES (12, 436037, 'Lot')[0m
[1m[35m (1.0ms)[0m COMMIT
Redirected to http://localhost:3000/admin/events/18342/lots/mass_new
Completed 302 Found in 41ms (ActiveRecord: 19.0ms)
Started GET "/admin/events/18342/lots/mass_new" for 127.0.0.1 at 2013-05-24 11:02:56 -0600
[1m[36mSQL (0.0ms)[0m [1mSELECT DISTINCT `domains`.id FROM `domains` LEFT OUTER JOIN `content_options` ON `content_options`.`contentable_id` = `domains`.`id` AND `content_options`.`contentable_type` = 'Domain' LEFT OUTER JOIN `companies` ON `companies`.`id` = `domains`.`company_id` LEFT OUTER JOIN `content_options` `content_options_companies` ON `content_options_companies`.`contentable_id` = `companies`.`id` AND `content_options_companies`.`contentable_type` = 'Company' WHERE `domains`.`name` = 'dvauction.com' LIMIT 1[0m
[1m[35mSQL (0.0ms)[0m SELECT `domains`.`id` AS t0_r0, `domains`.`company_id` AS t0_r1, `domains`.`name` AS t0_r2, `domains`.`title` AS t0_r3, `domains`.`contact` AS t0_r4, `domains`.`latitude` AS t0_r5, `domains`.`longitude` AS t0_r6, `domains`.`meta` AS t0_r7, `domains`.`street_1` AS t0_r8, `domains`.`street_2` AS t0_r9, `domains`.`city` AS t0_r10, `domains`.`state` AS t0_r11, `domains`.`zip` AS t0_r12, `domains`.`country` AS t0_r13, `domains`.`phone_1` AS t0_r14, `domains`.`phone_2` AS t0_r15, `domains`.`phone_3` AS t0_r16, `domains`.`fax` AS t0_r17, `domains`.`email` AS t0_r18, `domains`.`url` AS t0_r19, `domains`.`legacy_id` AS t0_r20, `domains`.`require_banking_from_user` AS t0_r21, `domains`.`analytics` AS t0_r22, `domains`.`redirect_back_to_dvauction` AS t0_r23, `domains`.`created_at` AS t0_r24, `domains`.`updated_at` AS t0_r25, `content_options`.`id` AS t1_r0, `content_options`.`contentable_id` AS t1_r1, `content_options`.`contentable_type` AS t1_r2, `content_options`.`key` AS t1_r3, `content_options`.`content` AS t1_r4, `content_options`.`created_at` AS t1_r5, `content_options`.`updated_at` AS t1_r6, `companies`.`id` AS t2_r0, `companies`.`name` AS t2_r1, `companies`.`domain_name` AS t2_r2, `companies`.`use_amazon_ses` AS t2_r3, `companies`.`created_at` AS t2_r4, `companies`.`updated_at` AS t2_r5, `content_options_companies`.`id` AS t3_r0, `content_options_companies`.`contentable_id` AS t3_r1, `content_options_companies`.`contentable_type` AS t3_r2, `content_options_companies`.`key` AS t3_r3, `content_options_companies`.`content` AS t3_r4, `content_options_companies`.`created_at` AS t3_r5, `content_options_companies`.`updated_at` AS t3_r6 FROM `domains` LEFT OUTER JOIN `content_options` ON `content_options`.`contentable_id` = `domains`.`id` AND `content_options`.`contentable_type` = 'Domain' LEFT OUTER JOIN `companies` ON `companies`.`id` = `domains`.`company_id` LEFT OUTER JOIN `content_options` `content_options_companies` ON `content_options_companies`.`contentable_id` = `companies`.`id` AND `content_options_companies`.`contentable_type` = 'Company' WHERE `domains`.`name` = 'dvauction.com' AND `domains`.`id` IN (6)
Processing by Admin::LotsController#mass_new as HTML
Parameters: {"event_id"=>"18342"}
[1m[36mUser Load (1.0ms)[0m [1mSELECT `users`.* FROM `users` WHERE `users`.`company_id` = 2 AND `users`.`id` = 140742 LIMIT 1[0m
[1m[35mPermission Load (0.0ms)[0m SELECT `permissions`.* FROM `permissions` WHERE `permissions`.`user_id` IN (140742) ORDER BY priority ASC, subject_id ASC
[1m[36mEvent Load (0.0ms)[0m [1mSELECT `events`.* FROM `events` WHERE `events`.`id` = 18342 LIMIT 1[0m
[1m[35mImage Load (1.0ms)[0m SELECT `images`.* FROM `images` JOIN image_containers ON image_containers.image_id = images.id LEFT JOIN lots ON lots.id = image_containers.imageable_id AND imageable_type = 'Lot' WHERE `images`.`catalog` = 1 AND ((image_containers.imageable_type = 'Event' AND image_containers.imageable_id = 18342) OR (image_containers.imageable_type = 'Lot' AND lots.event_id = 18342)) GROUP BY image_id ORDER BY image_file_name
[1m[36mImage Load (5.0ms)[0m [1mSELECT `images`.* FROM `images` JOIN image_containers ON image_containers.image_id = images.id LEFT JOIN lots ON lots.id = image_containers.imageable_id AND imageable_type = 'Lot' WHERE `images`.`catalog` = 0 AND ((image_containers.imageable_type = 'Event' AND image_containers.imageable_id = 18342) OR (image_containers.imageable_type = 'Lot' AND lots.event_id = 18342)) GROUP BY image_id ORDER BY image_file_name[0m
[1m[35mVideo Load (2.0ms)[0m SELECT `videos`.* FROM `videos` JOIN video_containers ON video_containers.video_id = videos.id LEFT JOIN lots ON lots.id = video_containers.videoable_id AND videoable_type = 'Lot' WHERE ((video_containers.videoable_type = 'Event' AND video_containers.videoable_id = 18342) OR (video_containers.videoable_type = 'Lot' AND lots.event_id = 18342)) GROUP BY video_id ORDER BY video_file_name
Rendered admin/lots/_collection_subnavigation.html.erb (2.0ms)
Rendered admin/lots/mass_new.html.erb within layouts/admin (10.0ms)
[1m[36mDeploymentNotice Exists (0.0ms)[0m [1mSELECT 1 AS one FROM `deployment_notices` WHERE `deployment_notices`.`deployed` = 0 LIMIT 1[0m
[1m[35m (0.0ms)[0m SELECT COUNT(*) FROM `domains` WHERE `domains`.`company_id` = 2
Completed 200 OK in 42ms (Views: 24.0ms | ActiveRecord: 9.0ms)
HTML-вывод:
<input id="lots_1369421745.947125_lot_number" name="lots[1369421745.947125][lot_number]" type="hidden" value="101z">
<input id="lots_1369421745.947125_lot_number" name="lots[1369421745.947125][lot_number]" type="hidden" value="115z">
<input id="lots_1369421745.947125_lot_number" name="lots[1369421745.947125][lot_number]" type="hidden" value="161z">
<input id="lots_1369421745.948125_lot_number" name="lots[1369421745.948125][lot_number]" type="hidden" value="20z">
<input id="lots_1369421745.948125_lot_number" name="lots[1369421745.948125][lot_number]" type="hidden" value="20z">
<input id="lots_1369421745.948125_lot_number" name="lots[1369421745.948125][lot_number]" type="hidden" value="47z">
<input id="lots_1369421745.948125_lot_number" name="lots[1369421745.948125][lot_number]" type="hidden" value="87z">
<input id="lots_1369421745.948125_lot_number" name="lots[1369421745.948125][lot_number]" type="hidden" value="rock_on">
Текст Входы:
<input id="lots_1369421745.948125_high_range" name="lots[1369421745.948125][high_range]" type="text">
<input id="lots_1369421745.948125_low_range" name="lots[1369421745.948125][low_range]" type="text">
Вы можете вставить вывод журнала сервера. – cortex
Я отправил его для вас. Его когда сообщение вызывается и сразу после завершения – user1977840
Используя веб-инспектор Chrome или Firebug, убедитесь, что у вашего 8 текстовых и скрытых полей есть правильное имя. например ''. – cortex