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

View helper is not html safe #9

Closed
romaslmd opened this issue Mar 1, 2016 · 5 comments
Closed

View helper is not html safe #9

romaslmd opened this issue Mar 1, 2016 · 5 comments

Comments

@romaslmd
Copy link

romaslmd commented Mar 1, 2016

Hi,
found this thing recently:

rails (4.2.1)
material_icons (2.0.1)
bootstrap-material-design (0.2.2)

(note: only on production env)
RAILS_ENV=production

# views/.../_action.html.slim
button.btn[type="submit"]
  = material_icon.search.md_18

output was a link with raw inner html as text

<button class="btn" type="submit"><i class="material-icons md-18 ">search</i></button>

but with

# views/.../_action.html.slim
button.btn[type="submit"]
    = material_icon.search.md_18.to_s.html_safe

all worked fine.

@Angelmmiguel
Copy link
Owner

Hello @romaslmd,

When you use the helper, it returns an instance of MaterialIcon model. When to render it into the view, to_s method is called. This method uses content_tag, a helper provided by ActionView. Returned string of this method is html_safe, as you can see in ActionView::Helpers::TagHelper line 146.

The problem can come from Slim template engine, I will check it. Can you tell me the version of Slim?

Thanks!

@romaslmd
Copy link
Author

romaslmd commented Mar 1, 2016

slim (3.0.6)
slim-rails (3.0.1)

@romaslmd
Copy link
Author

romaslmd commented Mar 3, 2016

@Angelmmiguel
U r right, problem related to Slim.
probably best option is to use double equal sign in view:

== material_icon.search

@Angelmmiguel
Copy link
Owner

Okey @romaslmd. I will close this issue and add a section in README. However, I will investigate it to report this if it's a Slim bug.

Thanks!

Angelmmiguel pushed a commit that referenced this issue Mar 3, 2016
@Angelmmiguel
Copy link
Owner

Added to Readme.

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