Rails - adjusting the number of spaces using Slim

I recently switched to slim and so far everything is going well. One thing I noticed after running the scaffold for one of my model views:

= link_to 'Edit', edit_movie_path(@movie)
'|
= link_to 'Back', movies_path

      

Unlike erb, there is no space in front of the pipe that displays these two links like

Edit| Back

As a newbie with slim, I was wondering if it was possible to add space before and after characters.

I also noticed that on the same scaffold there was no space separating colons from the text. For example:

Title: Rush Hour

Title:Rush Hour

To fix this, I had to either add a space right after the word name or insert one quote directly below.

# Option 1
p
  b Title: # Add space where the hashtag is currenty
  = @movie.title

# Option 2    
p
  strong Title: 
'
  = @movie.title

      

Is there an alternative to the two? I find that for the first addition, the invisible space may not be obvious to other developers / someone going back to the code, and the second adds a completely new line for just one character.

+3


source to share


1 answer


According to the documentation

You can force Slim to add trailing spaces after the tag by adding a>.

b> Title: 
=@movie.title

      

For your second (actually first) problem, after I browsed this site I came up with this



| #{link_to 'Edit', edit_movie_path(@movie)} | #{link_to 'Back', movies_path}

      

the |

tells thin verbatim to interpret the next line, and the two ruby ​​link_to statements are separated by*space*|*space*

Also this works

=' link_to 'Edit', edit_movie_path(@movie)
'|
= link_to 'Back', movies_path

      

+5


source







All Articles