leikind / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
MIT License
537 stars 215 forks source link

Issue rendering wice_grid #267

Closed adusak closed 8 years ago

adusak commented 8 years ago

Hi this isn't a huge issue, but for some reason when I use slim for my grid partial, it is rendered as escaped html code in production environment.

When I rewrote it to erb (which is nicer after all) it works fine.

Just thought this was a weird issue.

Thank for your library.

leikind commented 8 years ago

WiceGrid view code is just helpers. Functions with blocks. Why intermingle this with Slim or HAML at all? It's an artificially created problem. The suggested approach is putting WiceGrid functions into their own erb files, one grid - one file, or into helper files

adusak commented 8 years ago

I know, and I did that in the end. As I said it isn't a problem as much as it is a curiosity. That it worked fine in development environment but not in production.

Sorry for opening and Issue for this, just wanted to share it.

leikind commented 8 years ago

It's OK. Years ago, in the Stone Age of Rails, this library had an ERB mode where you could intermingle such a helper with ERB like this:


<% grid do %>
  <% column do |g| %>
    <p><%= g.id%></p>
  <% end %>
<% end %>

but then I realized this was not good and removed it

heisee commented 8 years ago

Hi, I debugged this and found out, that .html_safe at the end of the block helps:

= grid(@records_grid) { |g| my_grid_block(g) }.html_safe

It doesn't look like it's unsafe to do this, since when pretty mode is true, it's html_safe? by default.

To see this problem in development you may turn of pretty printing in slim in config/environments/development.rb:

Slim::Engine.set_options pretty: false

I can't say if it's a bug in wice_grid or in slim. I just guess, that it has to do with the usage of content_tag or any other callbacks of the rendering engine in wice_grid_view_helpers.rb