首页 > 解决方案 > 阻止 f.range_field 提交数据,除非与

问题描述

我有以下 f.range_field 在控制器中调用我的更新方法:

= f.range_field :feeling, :in => 1..3, :step => '1'

控制器:

if @workout.update_attributes(workout_params)
  redirect_to team_user_workouts_path(current_user.team,
    current_user, athlete: params[:athlete])
else
  render(:edit, athlete: params[:athlete])
end

我通常会使用 select_field include_blank: 'choose',这将确保如果未与选择字段交互 - 特定参数不会提交。如何使用范围字段实现相同的效果?现在,即使我不与它交互,它也会提交。

标签: ruby-on-rails

解决方案


推荐阅读