如何在带有Rails的表单中添加if语句

时间:2019-06-13 16:04:04

标签: ruby ruby-on-rails-3 ruby-on-rails-4

我正在尝试根据sku(将由sku确定国家/地区,由国家/地区决定运输方式)将这种逻辑实施为形式

country = order&.shop&.country
    if (READY_FOR_SCHOOL_SKUS + STICKER_BOOK_SKUS).include?(product.sku)
      if country == "uk"
        shipping_option = ShippingOption.find_by(name: "RoyalMail48")
      else
        shipping_option = ShippingOption.find_by(name: "TPLP")
      end
      return shipping_option
    end
    if (DICTIONARY_SKUS + WORD_OF_DAY_SKUS).include?(product.sku)
      if country == "uk"
        shipping_option = ShippingOption.find_by(name: "RoyalMail48")
      else
        shipping_option = ShippingOption.find_by(name: "standard_3_to_10_days")
      end
      return shipping_option
    end
    if (RFS_STICKER_BOOK_SKUS + USA_SUBSCRIPTION_SKUS + UK_SUBSCRIPTION_SKUS).include?(product.sku)
      if country == "uk"
        shipping_option = ShippingOption.find_by(name: "dhl")
      else
        shipping_option = ShippingOption.find_by(name: "TPLP")
      end
      return shipping_option
    end
<% @product.product_shop_shipping_options.uniq(&:shop).each_with_index do |psso, i|%>
  <%= f.fields_for :product_shop_shipping_options, psso do |s| %>
    <%= s.label psso.shop.shopify_shop_name %>
    <%= s.hidden_field :shop_id %>
    <%= s.grouped_collection_select :shipping_option_id, @fulfilment_centres, :shipping_options, :name, :id, :name, {prompt: 'Select shipping option'}, { class: 'form-control'} %>
  <% end %>
<% end %>

0 个答案:

没有答案