design patterns - Rails - use code(css, js, html) from server on client side -


i had application rails built bootstrap , simple form. here have show ui patterns how like. means have show patterns menu bar, accordian patterns examples in application. storing pattern code html,css,js in database.

here requirement have show actual code pattern view stored record(css,js,html) without css/js conflicts.

how can eneter html,css,js code dynamically in partial or page show in fancybox in rails.

thanks in advance.

just use html_safe or raw render content normal string on views. instance:

in controller:

@x = your_code_from_db 

in view:

<%= @x.html_safe %> # <%= raw @x %> ok in case 

notice: can use html_safe on models, raw declared on helper, can use on controllers , views.

-- edit --

more example:

on controller:

@hello = 'alert("hi");' @body = 'body{ background: red; }' 

on view:

<script type="text/javascript" charset="utf-8">   <%= raw @hello %> </script>  <style type="text/css" media="all">   <%= @body.html_safe %> </style> 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -