Hi, I have a partial (_contact.html) which looks something like this <script id="contact_template" type="text/html"> <h2><%= contact.name %></h2> <p><%= contact.id %></p> </script> I want to render this to the view exactly as it is show there. I don''t want the erb tags evaluating. When I try and render this using: render :partial => ''contact.html'' I get an error because it is trying to evaluate the erb tags and call the name method on the non-existent contact object. I simply want to render the text, as it is written, to the view. How can I do this? The reason for it is that I am investigating ways of JSON templating (http://ejohn.org/blog/javascript-micro-templating/). I am ultimately aiming to make some of my partials reuseable between the rails code and the javascript code so that I only have to maintain them in one place. I want to carry on using <%= %> in the JSON templates. How can I tell rails just to render the partial as text and not try to evaluate it? Thanks -- Posted via http://www.ruby-forum.com/.
The only way I would think you can do it is by reading the template file into a variable in your controller and in your view escaping the string. Not pretty. Pepe On May 19, 3:45 pm, Tim Conner <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > I have a partial (_contact.html) which looks something like this > > <script id="contact_template" type="text/html"> > <h2><%= contact.name %></h2> > <p><%= contact.id %></p> > </script> > > I want to render this to the view exactly as it is show there. I don''t > want the erb tags evaluating. When I try and render this using: > render :partial => ''contact.html'' > > I get an error because it is trying to evaluate the erb tags and call > the name method on the non-existent contact object. I simply want to > render the text, as it is written, to the view. How can I do this? > > The reason for it is that I am investigating ways of JSON templating > (http://ejohn.org/blog/javascript-micro-templating/). I am ultimately > aiming to make some of my partials reuseable between the rails code and > the javascript code so that I only have to maintain them in one place. > I want to carry on using <%= %> in the JSON templates. How can I tell > rails just to render the partial as text and not try to evaluate it? > Thanks > -- > Posted viahttp://www.ruby-forum.com/.
2009/5/20 pepe <Pepe-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org>> > The only way I would think you can do it is by reading the template > file into a variable in your controller and in your view escaping the > string. > > Not pretty. > > PepeI think that having once read the template file into a variable in the controller it can be displayed without escaping in the view. The string will not be parsed as erb Colin> > > On May 19, 3:45 pm, Tim Conner <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > Hi, > > I have a partial (_contact.html) which looks something like this > > > > <script id="contact_template" type="text/html"> > > <h2><%= contact.name %></h2> > > <p><%= contact.id %></p> > > </script> > > > > I want to render this to the view exactly as it is show there. I don''t > > want the erb tags evaluating. When I try and render this using: > > render :partial => ''contact.html'' > > > > I get an error because it is trying to evaluate the erb tags and call > > the name method on the non-existent contact object. I simply want to > > render the text, as it is written, to the view. How can I do this? > > > > The reason for it is that I am investigating ways of JSON templating > > (http://ejohn.org/blog/javascript-micro-templating/). I am ultimately > > aiming to make some of my partials reuseable between the rails code and > > the javascript code so that I only have to maintain them in one place. > > I want to carry on using <%= %> in the JSON templates. How can I tell > > rails just to render the partial as text and not try to evaluate it? > > Thanks > > -- > > Posted viahttp://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---