Rails slim form_for tag

4.4k views Asked by At

I am having trouble getting a form to work after switching from regular ERB to slim files. Here is the form I am trying to have slim render:

= 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"

Here was the working code in regular ERB file

<%= 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 %>

This is the error I am currently getting:

undefined local variable or method `f'
1

There are 1 answers

2
Roman Kiselenko On BEST ANSWER

Most problem with slim it is indents try this(two space after 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"