循环内的第一个form_tag从未命中控制器动作

时间:2018-08-29 08:49:44

标签: ruby-on-rails forms loops

我在循环中有一个看起来像这样的表单:

- @templates.each do |template|  
  tr
    td.col-md-2
      = template.kind.capitalize
    td.col-md-9
      = form_tag(add_workout_from_template_path, method: :post) do
        = hidden_field_tag 'date', params[:date]
        = hidden_field_tag 'athlete', params[:athlete]
        = hidden_field_tag 'title', template.title
        = hidden_field_tag 'kind', template.kind
        = hidden_field_tag 'distance', template.distance
        = hidden_field_tag 'duration', template.duration
        = hidden_field_tag 'notes', template.notes
        = hidden_field_tag 'video', template.video

        = submit_tag(template.title, class: 'fake-button')
    td.col-md-1
      = link_to image_tag('cancel.png'),
        template_path(template),
        method: :delete

对于迭代2、3和4,它的作用就像一个超级按钮。每当我单击template.title时,表单就会执行,点击控制器并执行我想要的操作。它会打印此列表,我可以单击标题以将其添加到日历:

enter image description here

但是,当我单击第一个(其他20x ...)时,它从未在控制器中创建应有的内容,而只是创建了一个空白对象并重定向。当我尝试在控制器中加注时,它从未在第一个控制器上加注,因此由于某种原因似乎根本没有击中控制器?

我在这里做什么错了?

控制器代码:

def add_workout_from_template
  @athlete = User.find_by(slug: params[:athlete])
  @workout = Workout.create!(
    user: @athlete,
    date: params[:date],
    title: params[:title],
    kind: params[:kind],
    distance: params[:distance] || 0,
    duration: params[:duration] || 0,
    notes: params[:notes],
    video: params[:video]
  )

  redirect_to team_user_workouts_path(current_user.team,
    current_user, athlete: @athlete)
end

0 个答案:

没有答案
相关问题