Slim templates on Ruby on Rails, what are best practices

B.I. picture B.I. · Sep 18, 2013 · Viewed 14.7k times · Source

I have trouble understanding basic Slim syntax.

First question, how to do you enter new line (line break)?

Second request, could you please rewrite the following snippet, I suspect I didn't do it easy way?

- 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 its output:

Title a

tahrirlash (edit) | orqaga

Predmet nomi: english 5-7 year olds

O'quvchi darajasi: beginner

Kurs haqida ma'lumot

objectives b

Answer

Aman Garg picture Aman Garg · Sep 18, 2013

For new line, you should just use br like:

h1 Line1 content
br
h1 Line2 content

And about the above mentioned code, it can be rewrite like this:

-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