time_select的未定义方法



我试图使用局部传递的时间选择,但我得到以下错误

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

您可以这样做(从您提到的代码的最后一行开始):

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

如果没有trading_hour,则在Merchants controller action中构建trading_hours:

@merchant.trading_hours.build

PS:这是ERB(我只知道这个:))

您提到了accepts_nested_attributes_for:trading_hours如果您的交易时间模型中有open_time列,下面的代码可能会有所帮助:

如果你在应用程序中使用simple_form

= hour_fields.simple_fields_for :trading_hours do |nest_form|
  = nest_form.open_time

相关内容

  • 没有找到相关文章

最新更新