Reputation: 9362
How can i include render response of a view inside another , but dumped.
like i am currently using:
css: "<%= render :partial => "myurl/blah", :formats=> [:css], :layout => false %>",
( in a rendered js file, where i am creating a json object and including various other files too.. )
The response here is like this :
css: "#utilities {width: 800px;}
#utilities p,
#utilities ul {margin-bottom: 1em;}
#utilities_scroll {height:500px; padding:0 10px 0 10px; overflow:scroll;}
#utilities_scroll_inner {width: 733px;}
#utilities-search-form {margin-top: 20px;} .. ."
However i want dump of it like this :
css: "#utilities {width: 800px;}\n#utilities p,\n#utilities ul {margin-bottom: .. "
EDIT:
In response to:
css : <%= eval("render :partial => 'myurl/blah', :formats=> [:css], :layout => false").dump %>
It is dumping the html but slightly incorrect way,
See in rails console :
a = "fdjasdlkfs 32$#%$#^$%^<>tv5$ ;'" # => "fdjasdlkfs 32$#%$#^$%^<>tv5$ ;'"
a.dump #=> "\"fdjasdlkfs 32$#%$#^$%^<>tv5$ ;'\""
That would be correct way but , in html with the line i'm including , the response is as :
(if i have in myurl/blah.css file as : "fdjasdlkfs 32$#%$#^$%^<>tv5$ ;'"
The result is
css : "\"fdjasdlkfs 32$#%$#^$%^<>tv5$ ;'\"\n"
see the difference as < > "
are transformed very differently in both cases..( i needed it as per first format"
Upvotes: 0
Views: 300
Reputation: 9362
Thanks to Vik for efforts... But after long hours of search i ended up as :
css : <%= JSON.dump(render :partial => "abc/url", :formats=> [:css], :layout => false).html_safe %>
css: <%= eval("render :partial => 'blah/blah', :formats=> [:css], :layout => false").dump.html_safe%>,
css: <%= eval("render :partial => 'blah/blah', :formats=> [:css], :layout => false").to_json.html_safe%>,
as solution for the problem.... I have just started up on Ruby,rails and find strange there is no proper documentation regarding all these small things...hope this helps someone...
however in my case i ended up using for my solution as : ( a little diff from question ) in controller :
@cssrender = JSON.dump(render_to_string(:file => "blah/blah", :layout => false , :formats =>[:css]))
and in view just css :<%[email protected]_safe%>
Upvotes: 0
Reputation: 5961
Use eval . I never tried this before but it would work .
Try :
css : <%= eval("render :partial => 'myurl/blah', :formats=> [:css], :layout => false") %>
Upvotes: 1