-
Notifications
You must be signed in to change notification settings - Fork 237
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
Different behavior of html_safe in dev/prod #305
Comments
Not sure I understand the problem? |
This is documented here: https://github.com/apotonick/cells#invocation-styles Calling the method manually is not official API and up to you. This is also discussed at the end of chapter 8 in the Trailblazer book, where you can call states manually and avoid Capybara wrapping. |
Uh-oh, excuse me. I changed title of this issue (I realized the real problem while submitting and re-wrote text, but forgot about title). Now, the problem is different behavior in environments: when I was in dev and used Maybe, in staging & production module |
Ah ok, thanks, now I understand your pain. I can't say it for sure, but if Can you confirm that? When you do |
Just made a clean check — rendered the same cell subsequently with I observe this behavior on cells both with and without caching, don't think it is related. Extensions inclusion: I see your point and made a little investigation, with no luck though. I'll try digging deeper. |
I concur. This looks strange in the view: = cell('worktime', worktime).() Shouldn't view helper return html_safe output by default? Besides = cell('worktime', collection: worktimes) Returns an html_safe string. |
That's right, in views, |
Yep, I understand, but if we are striving for consistency then maybe adding something like this to base class would be reasonable? def to_s
call.html_safe
end |
..which is exactly what happens: https://github.com/apotonick/cells/blob/master/lib/cell/rails.rb#L47 I just messages you on IRC to please join Trailblazer gitter channel. |
@apotonick Any news about this issue? It has blocked our project. What can I help? |
I have zero clue what might be wrong, as it works for me in many projects. Do you have a minimal cell that can provoke this error? Or does it happen with nested cells? |
It only occurs to SLIM in production. In development it is fine. And calling cell/concept with collection would be fine as well. It seems that this problem does not happen to HAML anymore. @apotonick |
I think I got it fixed by using '==' instead of '='. Maybe that is the correct way to use cells in slim. However, it is just strange that development and production have different behaviours. |
+1 for this problem in slim. |
So, should we simply document that in |
I found this old issue and felt it would be nice if it can be finally resolved. _TL/DR_: add to your cells a method In details, it seems the problem is in Slim engine's test for = cell(:test)
# ERB equivalent: <%= ::Temple::Utils.escape_html_safe((cell(:test))) %> The method def escape_html_safe(html)
html.html_safe? ? html : escape_html(html)
end (This method may or may not be called depending on a combination of settings — I guess that's the reason why some folks see different behavior in dev/prod, including me.) This leads to: = cell(:test).html_safe? # false
= cell(:test).to_s.html_safe? # true
= cell(:test).call.html_safe? # true As we really do cell html_safing in Rails, it seems OK to add its sister method somewhere near: # lib/cell/rails.rb
def call(*)
super.html_safe
end
def html_safe?
true
end This was tested in cells 4.0.5 and cells 4.1.3 + cells-rails 0.0.6. What do you think, can we add this? I can make a pull request if you give it a go. |
Yes, this doesn't make sense to me, but it makes sense in Rails. 🤔 How could we test this? This must go to the cells-rails gem, though. |
I did fresh installation of latest Rails and Slim, and tested both with old cells (4.0.5) and new cells + cells-rails (4.1.3 + 0.0.6). That is, I added method Would this suffice? If not, can you suggest other tests to do? |
I've made a pull request — take a look at it when you have a chance: https://github.com/trailblazer/cells-rails/pull/12 |
The PR is gone. Creating a new initializer (like module Cell
module RailsExtensions
module ViewModel
def html_safe?
true
end
end
end
end |
In production & staging environments the result of cell rendering is returned as escaped HTML string. In order to get raw result (as excepted) I have to do
cell(...).call
:Dev env works well.
Gem versions:
rails 4.2.2
cells 4.0.1
cells-slim 0.0.3
Here's config:
Any suggestions?
The text was updated successfully, but these errors were encountered: