Thin Ruby on Rails templates, what are the best practices

I have trouble understanding the syntax of the base Slim.

The first question is how to enter a new line (line break)?

Second query, could you rewrite the next fragment, I suspect that I did not do this easily?

- provide(:title, @course.title)                                                                                                          

.row
  aside.span4
    section
      h1 = @course.title.capitalize

      => link_to t('ui.edit'), edit_course_path(@course)
      '|
      => link_to t('ui.back'), courses_path

      p
        b #{t('activerecord.attributes.subject.title')}:
        | #{@course.subject.title}

      p
        b #{t('activerecord.attributes.student_level.title')}:
        | #{@course.student_level.title}

      h4 #{t('activerecord.attributes.course.objectives')}
      = @course.objectives

This is his conclusion:

Heading a

tahrirlash (change) | orqaga

Predmet nomi: English 5-7 years old

O'quvchi darajasi: beginner

Kurs haqida ma'lumot

goals b

+4
source share
2 answers

For a new line, you just need to use br:

h1 Line1 content
br
h1 Line2 content

And about the above code, it can be rewritten as follows:

-provide(:title,@course.title)                                                    
.row
  aside.span4
    section
      h1 = @course.title.capitalize

      = link_to t('ui.edit'), edit_course_path(@course)
      '|
      = link_to t('ui.back'), courses_path

      p
        b = t('activerecord.attributes.subject.title')
        |:     
        = @course.subject.title

      p
        b = t('activerecord.attributes.student_level.title')
        |: 
        = @course.student_level.title

      h4 = t('activerecord.attributes.course.objectives')
      = @course.objectives
+7
source

br slim:

1. :

h1
  | Hello
  br
  | world

html:

<h1>Hello<br>world</h1>

2. :

p
  = f.label :title
  br
  = f.text_field :title

html:

<p>
  <label for="question_title">Title</label><br>
  <input name="question[title]" id="question_title" type="text">
</p>
0

Source: https://habr.com/ru/post/1502855/


All Articles