Ruby: v2.5.7 Rails: v5.2.4.4 gem slim: v4.1.0
= form_with model:@team, local:true do |f|
= render 'layouts/error_message', model: f.object
.input
= f.label :name
= f.text_field :name
.input
= f.label :introduction
= f.text_area :introduction
= f.submit
This time, I introduced slim
which is one of the Gem of Ruby on Rails, but I got an error immediately.
The content is![Screenshot 2020-10-11 12.24.41.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/613376/1675190f-a192-b820 -8887-b51b14351f45.png)
With NameError
undefined local variable or method f' for #<#<Class:0x00007fef406b53c8>:0x00007fef35880668>
It means that the specified f is not defined. Even though the block variable described in form_with says f ... I wondered if there was a way to write form_with peculiar to slim, so I was researching various things. As a result, it was solved by correcting as follows.
= form_with model: @team, local: true do |f|
/Each paragraph indented
= render 'layouts/error_message', model: f.object
.input
= f.label :name
= f.text_field :name
.input
= f.label :introduction
= f.text_area :introduction
= f.submit
It was an indentation adjustment ... it's simple to understand ...
I didn't need ʻend or
() `, so I was wondering how to determine the scope of application of form_with, but it is identified by indentation. So that's it...
I noticed through this error. Lol
It's a simple thing, but I'm addicted to it, so I'll post it.
Even so, it takes some getting used to, but even if you don't need a few descriptions and parentheses, the description is considerably simplified and the code is easy to write and easy to read. In addition, it seems that rendering is a little faster, so it's just a good point, slim.
Recommended Posts