Rails路由很奇怪

时间:2012-04-14 18:19:09

标签: ruby-on-rails routes

突然间,我的Rails应用程序很奇怪。如果我在编辑页面上附加图像并提交表单,则会调用show操作而不是更新操作。如果我没有附上任何图片,那就没关系。

路线

namespace :admin do
  resources :products do
    collection do
      get :download_images
      get :all_styles
      post :compress_images
    end
  end
end

视图

%h1 Edit Product

= form_for [:admin, @product], :html => {:multipart => true} do |f|
  - if f.object.accessory?
    = render 'form_accessory', :f => f
  - else
    = render 'form', :f => f

[_form partial]
:javascript
  function exclusiveCheck(check_box) {
    if (check_box.checked) {
      $('#pictures_fieldset .is_main').attr('checked', false);
      check_box.checked = true;
    }
  }
- error_messages_for f.object

%fieldset.span-23
  %legend
  .row
    = f.label :category_id, :class => "required"
    %br
    = f.select :category_id, array_of_categories('garment'), :include_blank => true
    = f.check_box :new_in_category
    = image_tag "new_icon.png"

  .row
    = f.label :style_no, :class => "required"
    %br
    = f.text_field :style_no, :style => "width: 5em;"

  .row
    = f.label :name, :class => "required"
    %br
    = f.text_field :name

  .row
    = f.label :fabric_info, :class => ""
    %br
    = f.text_field :fabric_info, :style => "width: 90%;"

  .row
    = f.label :lb_per_piece, "Weight", :class => "required"
    %br
    = f.text_field :lb_per_piece, :style => "width: 3em;"

  .row
    .span-3
      = f.label :price, :class => "required"
      %br
      = f.text_field :price, :style => "width: 6em;"
    .span-3
      = f.label :original_price, :class => ""
      %br
      = f.text_field :original_price, :style => "width: 6em;"
    .span-10
      %label Discount Rate
      %br
      = text_field_tag :percent, nil, :style => "width: 3em;", :id => "percent"
      = "%"
      = link_to_function "Set", "setPrice();"
      = f.check_box :new_in_sale
      = image_tag "new_icon.png"
  .row
    = f.label :video, :class => ""
    %br
    = f.text_field :video, :style => "width: 15em;"
    (Upload videos to data.ohyesfashion.com at ~/files/videos directory.)

  .row
    = f.label :available_on
    %br
    = f.text_field :available_on, :class => 'date'

  .row
    = f.check_box :active
    = f.label :active, :class => ""

  .row
    = f.check_box :new_arrival
    = f.label :new_arrival, :class => ""
    = f.check_box :new_in_new_arrival?
    = image_tag "new_icon.png"

  .row
    = f.check_box :best
    = f.label :best, :class => ""
    = f.check_box :new_in_best
    = image_tag "new_icon.png"
.span-24.last
  %button.button.positive(type="submit")
    = icon_for(:accept, "Save")

%fieldset
  %legend Sizes
  - Product::SIZES.each do |size|
    .span-2
      = size.to_s.upcase
      = f.select size, [*0..20].map { |i| i.to_s }

.span-24
  .span-12
    %fieldset
      %legend Descriptions
      - Description.order("code, name").each do |description|
        .row
          = check_box_tag "descriptions[]", description.id, f.object.descriptions.include?(description)
          = "[#{description.code}]"
          = description.name
      .row
        New Description 
        = text_field_tag :new_description_name
  .span-12.last
    %fieldset(style="float: right;")
      %legend Colors
      .span-11
      - Color.order("name").each do |color|
        .row
          .span-1
            = check_box_tag "colors[]", color.id, f.object.colors.include?(color)
          .span-4
            = color_box color
          .span-3
            = check_box_tag "sold_out_colors[]", color.id, (f.object.colors.include?(color) and Colorship.sold_out?(f.object, color))
            Sold Out
          .span-2
            = check_box_tag "is_new_colors[]", color.id, (f.object.colors.include?(color) and Colorship.is_new?(f.object, color))
            New

.span-24.last
  %button.button.positive(type="submit")
    = icon_for(:accept, "Save")


- (15 - f.object.pictures.size).times { f.object.pictures.build }
%fieldset#pictures_fieldset
  %legend Images
  .row
    = f.label :model_id, "Model"
    = f.select :model_id, PhotoModel.all.map { |i| [i.name, i.id] }, :include_blank => true
  %br
  = f.fields_for :pictures do |ff|
    .span-7(style="height: 150px;")
      - if ff.object.new_record?
        = ff.file_field :image
      - else
        = image_tag ff.object.image.url(:w45)
        %br
        = ff.object.image_file_name
        %br
        = ff.check_box :is_main, :onclick => "exclusiveCheck(this)", :class => "is_main"
        Title
        %br
        = ff.check_box "_destroy"
        Delete


.span-24.last
  = link_to icon_for(:back, "Back"), :back, :class => "button negative"
  %button.button.positive(type="submit")
    = icon_for(:accept, "Save")

:javascript

  function setPrice() {
    if ($('#product_original_price').val() != '' && $('#percent').val() != '') {
      var originalPrice = parseFloat($('#product_original_price').val());
      var percent = parseFloat($('#percent').val());
      $('#product_price').val(originalPrice * (100 - percent) / 100.0);
    }
  }

知道发生了什么事吗?过去工作得很好。

0 个答案:

没有答案
相关问题