如果在不同的模型上满足条件,我正在尝试在表单中显示某些字段。
这是示例:
<%= form_for(@workout) do |f| %>
<%= f.fields_for :workout_exercises do |s| %>
<%= s.collection_select :exercise_id, Exercise.all, :id, :name, { :include_blank => ""} %>
<%= s.label :sets %>:
<%= s.number_field :set %>
<% if @exercise.is_cardio == true %>
<%= s.label :time %>(Minutes):
<%= s.number_field :time %>
<% end %>
<% end %>
<%= f.submit %>
<% end %>
上面给出了一个无方法错误is_cardio
是有氧运动是练习表中的布尔字段
谢谢!
编辑:
class Exercise < ActiveRecord::Base
has_many :workout_exercises
has_many :workouts, :through => :workout_exercises
end
class Workout < ActiveRecord::Base
has_many :workout_exercises
has_many :exercises, :through => :workout_exercises
class WorkoutExercise < ActiveRecord::Base
belongs_to :exercise
belongs_to :workout
end
编辑2:
具体来说,这是我得到的错误:
undefined method `is_cardio' for #<Array:0x007fcd3bb93dd0>