Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get rid of blank spaces in templates rendered by Rails 3.2.13 ERB/Erubis? #10742

Closed
wzup opened this issue May 23, 2013 · 1 comment
Closed

Comments

@wzup
Copy link

wzup commented May 23, 2013

Rails responses with a page full of blank spaces:

rails_render

The text from Rails guide:

config.action_view.erb_trim_mode gives the trim mode to be used by ERB. It defaults to '-'. See the ERB documentation for more information.

This is a code from gems\actionpack-3.2.13\lib\action_view\template\handlers\erb.rb:

# Specify trim mode for the ERB compiler. Defaults to '-'.
    # See ERB documentation for suitable values.
    class_attribute :erb_trim_mode
    self.erb_trim_mode = '-' # yes, trim mode is set by dafault

    # Default implementation used.
    class_attribute :erb_implementation
    self.erb_implementation = Erubis # Erubis is instead of ERB

  self.class.erb_implementation.new(
    erb,
    :escape => (self.class.escape_whitelist.include? template.mime_type),
    :trim => (self.class.erb_trim_mode == "-") # so :trim is true
  ).src`

From official Erubis docs:

Erubis deletes spaces around '<% %>' automatically, while it leaves spaces around '<%= %>'.
If you want leave spaces around '<% %>', add command-line property '--trim=false'.
Or add option :trim=>false to Erubis::Eruby.new().

So it is obvious that :trim => (self.class.erb_trim_mode == "-") will never remove spaces around <%= %>. Because there is no option in Erubis for it. And this is exactly seen on the picture above.

This line self.erb_implementation = Erubis informs that Rails implements Erubis instead of ERB.

But as written above the only trim mode Erubis supports is around <% %>.

So,

  1. How to get rid of blank spaces without switching to Slim, Haml, etc?
  2. Why Rail say See the ERB documentation for more information if default Erubis doesn't support ERB trim modes like <>%?

I use:
Rails 3.2.13
ruby 1.9.3p392 (2013-02-22) [i386-mingw32]
under Windows XP

@senny
Copy link
Member

senny commented May 24, 2013

This is not a support forum. Please use the mailing list to ask questions. You can read more in our contribution guidelines.

Thanks for your understanding.

@senny senny closed this as completed May 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants