从常规ERB切换到超薄文件后,我无法让表单正常工作。这是我试图修改渲染的形式:
= form_for @student, :url => students_path(@student), method: :post do |f|
= f.hidden_field :student_id, :value => current_user.id
= f.hidden_field :course_id, :value => group.id
= submit_tag "Join this Class!", :class => "btn btn-primary pull-right join-button"
以下是常规ERB文件中的工作代码
<%= form_for @student, :url => students_path(@student), method: :post do |f| %>
<%= f.hidden_field :student_id, :value => current_user.id %>
<%= f.hidden_field :course_id, :value => group.id %>
<%= submit_tag "+ Join", :class => "btn btn-primary pull-right join-button" %>
<% end %>
这是我目前得到的错误:
undefined local variable or method `f'
答案 0 :(得分:6)
缩小的最大问题是缩进尝试这个(form_for
之后的两个空格):
= form_for @student, :url => students_path(@student), method: :post do |f|
= f.hidden_field :student_id, :value => current_user.id
= f.hidden_field :course_id, :value => group.id
= submit_tag "Join this Class!", :class => "btn btn-primary pull-right join-button"