0

我在 Rails 中提交了一个表单,其中表单上的一些参数没有发布到数据库中,而是作为“null”传递。未发布的参数是:starthour:endhour,不知道为什么,但有时:rentend

我想不通..见下文

表单视图

<div class="gearside_date_top">
    <%= form_for LineItem.new do |f| %>
    <p><%= render :partial => "price" %> / 
        <%= f.select :day_or_hour, [['day', 'day'], ['hour', 'hour']], :id => 'day_or_hour' %>
    </p>
</div>
<script>
$('#line_item_day_or_hour').change(function() {
     if($('#line_item_day_or_hour').val() != 'hour') { 
     $('.hourlyshowhide').hide();
     $('#gear_daily').show();
     } 
     else {
     $('.hourlyshowhide').show();//else it is shown
     $('#gear_daily').hide();
     }
});
</script>
<div class="gearside_date_main">
    <h3 style="font-family: 'RockSaltRegular', 'JosefinSansStdLight', Helvetica, Arial, sans-serif;color: #71a41e; font-size: 16px; margin: 15px 0 5px 15px;">Rental Date</h3>      


    <%= f.text_field :rentstart, id: 'rentstart', :value => "Pickup"  %>
        <%= f.text_field :rentend, id: 'rentend', :value => "Drop Off"  %>
        <%= image_tag('calendar.png', :style => "float:left; padding-top: 8px") %>
        <%= f.hidden_field :gear_id, :value => @gear.id %>
        </br></br>
        <div class="gear_time_schedule hourlyshowhide">
        <span class="gear_time_schedule_container">
            <%= f.label :starthour, 'Pick Up Time', class: 'labeltext' %>
            <%= f.text_field :starthour, id: 'starthour', :value => "" %>
        </span>
        <span class="gear_time_schedule_container">
            <%= f.label :endhour, 'Drop Off Time', class: 'labeltext' %>
            <%= f.text_field :endhour, id: 'endhour', :value => "" %>
        </span>
    </div>
    <%= f.submit "", id: 'rent_it' %>
<% end %>
</div>
<script>
$('#starthour').timepicker({ 'step': 15 });
$('#endhour').timepicker({ 'step': 15 });
</script>

日志文件

Started POST "/line_items" for 127.0.0.1 at 2012-06-22 10:24:54 -0600
Processing by LineItemsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"MutF3dqAQpdtHtkvX1mTTxS+48styiHc1M94o8es3yA=", "line_item"=>{"day_or_hour"=>"hour", "rentstart"=>"06/05/2012", "rentend"=>"06/16/2012", "gear_id"=>"2"}, "commit"=>""}
  [1m[36mCart Load (0.3ms)[0m  [1mSELECT `carts`.* FROM `carts` WHERE `carts`.`id` = 28 LIMIT 1[0m
  [1m[35mGear Load (0.2ms)[0m  SELECT `gears`.* FROM `gears` WHERE `gears`.`id` = 2 LIMIT 1
  [1m[36mLineItem Load (0.3ms)[0m  [1mSELECT `line_items`.* FROM `line_items` WHERE `line_items`.`cart_id` = 28 AND `line_items`.`gear_id` = 2 LIMIT 1[0m
  [1m[35m (0.1ms)[0m  BEGIN
  [1m[36m (0.6ms)[0m  [1mUPDATE `line_items` SET `quantity` = 2, `updated_at` = '2012-06-22 16:24:54' WHERE `line_items`.`id` = 9[0m
  [1m[35m (13.5ms)[0m  COMMIT
  [1m[36mCart Load (0.4ms)[0m  [1mSELECT `carts`.* FROM `carts` WHERE `carts`.`id` = 28 LIMIT 1[0m
Redirected to http://localhost:3000/carts/28
Completed 302 Found in 76ms (ActiveRecord: 15.5ms)
4

1 回答 1

0

有两个问题。

第一个是日期格式,我在这里找到了答案Rails 3 jquery date picker date not save to database

第二个是 jquery 插件 jquery-timepicker-rails。我最终删除了供应商文件夹中的插件并安装了gem。这解决了我的问题。

于 2012-12-18T07:22:47.547 回答