0

パーシャルに渡されたローカルで時間選択を使用しようとしていますが、次のエラーが発生しています

undefined method `open_time' for #<Merchant:0x007fb41fd0aa90>

部分通話

= form_for @merchant, :url => admin_merchant_path(@merchant) do |form|
      #account-panel.mdl-tabs__panel
        = render :partial => 'venue', :locals => {:address_fields => form}
        = render :partial => 'hours', :locals => {:hour_fields => form}

部分的にレンダリング

.mdl-cell.mdl-cell--12-col
  /h3.mdl-typography--display-1.teal-heading= t('.trading_hours_title')
  - (0..6).each do |i|
    li.mdl-list__item.mdl-list__item--two-line
      span.mdl-list__item-primary-content
        = Date::DAYNAMES[i]
        span.mdl-list__item-sub-title
        = hour_fields.time_select :open_time, {:minute_step => 30, :ampm => true}

商人モデル

has_many :trading_hours, dependent: :destroy
accepts_nested_attributes_for :trading_hours

取引時間モデル

belongs_to :merchant
4

2 に答える 2

1

次のようなことができます(言及されたコードの最後の行から始めます):

<%= hour_fields.fields_for :trading_hours do |trading_field| %>
   <%= trading_field.time_select :open_time, {:minute_step => 30, :ampm => true} %>
<% end %>

そして、マーチャントコントローラーアクションビルドでtrading_hoursは、何も持っていない場合trading_hour:

@merchant.trading_hours.build

PS: これは ERB です (私が知っているのはこれだけです :) )

于 2016-10-18T08:59:10.603 に答える
0

accept_nested_attributes_for :trading_hours について言及しましたが、取引時間モデルに open_time 列がある場合、次のコードが役立つ場合があります。

アプリで simple_form を使用する場合

= hour_fields.simple_fields_for :trading_hours do |nest_form|
  = nest_form.open_time
于 2016-10-18T09:03:24.760 に答える