Rails slim form_for标签

时间:2014-11-13 17:34:21

标签: ruby-on-rails ruby-on-rails-4 slim-lang

从常规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'

1 个答案:

答案 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"