How can I get RoR to display html pulled directly from a database, without converting the tags. (e.g. if "<h1>Hello</h1>" is stored (as text) in a database, how can I get RoR NOT to corvert it to "<h1>Hello</h1>", but instead to just pass the tags along so that "Hello" displays in bold. I''m sure it''s just a simple method call, but I''ve been poking around and I can''t find anything. Thanks, -- Posted via http://www.ruby-forum.com/.
As far as I know, there shouldn''t be any problem doing this; Rails should do it by default. Unless you are calling h(text) before saving to the database or in your view, characters like < or > should not be converted to HTML entities. The question is, where did this HTML in your database come from? A text area in one of the forms in your app, or somewhere else? If it was saved directly from a text area, you shouldn''t be having a problem... -- Posted via http://www.ruby-forum.com/.
Alex Auritt
2006-Jul-18 18:18 UTC
[Rails] Re: Displaying HTML pulled directly from a database
So far I''ve been manually entering the html (for testing purposes) through the text areas on the scaffold-generated forms. So, I take it this shouldn''t be a problem. But you raise a good point. It hadn''t occured to me that actual data in the db might have the html entities instead of the desired ''<'' characters. Is there an easy way for me to check what''s actually in the db? Eleo wrote:> As far as I know, there shouldn''t be any problem doing this; Rails > should do it by default. Unless you are calling h(text) before saving > to the database or in your view, characters like < or > should not be > converted to HTML entities. > > The question is, where did this HTML in your database come from? A text > area in one of the forms in your app, or somewhere else? If it was > saved directly from a text area, you shouldn''t be having a problem...-- Posted via http://www.ruby-forum.com/.
James Ludlow
2006-Jul-18 18:25 UTC
[Rails] Re: Displaying HTML pulled directly from a database
On 7/18/06, Alex Auritt <alexauritt@gmail.com> wrote:> So far I''ve been manually entering the html (for testing purposes) > through the text areas on the scaffold-generated forms. So, I take it > this shouldn''t be a problem. > > But you raise a good point. It hadn''t occured to me that actual data in > the db might have the html entities instead of the desired ''<'' > characters. Is there an easy way for me to check what''s actually in > the db?Most every database has a client program, or there are dozens of different thrid-party options available. Check your database documentation.
Alex Auritt
2006-Jul-18 18:57 UTC
[Rails] Re: Displaying HTML pulled directly from a database
I check the data in the db (using the data browser on MySQL-front) and it looks fine -- no html entities. But still, the data is being converted: the final html file generated from the db, through the views, etc., contains the entities and not the plain html that I want to display. ??? Alex Auritt wrote:> So far I''ve been manually entering the html (for testing purposes) > through the text areas on the scaffold-generated forms. So, I take it > this shouldn''t be a problem. > > But you raise a good point. It hadn''t occured to me that actual data in > the db might have the html entities instead of the desired ''<'' > characters. Is there an easy way for me to check what''s actually in > the db? > > Eleo wrote: >> As far as I know, there shouldn''t be any problem doing this; Rails >> should do it by default. Unless you are calling h(text) before saving >> to the database or in your view, characters like < or > should not be >> converted to HTML entities. >> >> The question is, where did this HTML in your database come from? A text >> area in one of the forms in your app, or somewhere else? If it was >> saved directly from a text area, you shouldn''t be having a problem...-- Posted via http://www.ruby-forum.com/.
snacktime
2006-Jul-18 19:04 UTC
[Rails] Re: Displaying HTML pulled directly from a database
How exactly are you rendering it?
James Ludlow
2006-Jul-18 19:05 UTC
[Rails] Re: Displaying HTML pulled directly from a database
On 7/18/06, Alex Auritt <alexauritt@gmail.com> wrote:> I check the data in the db (using the data browser on MySQL-front) and > it looks fine -- no html entities. > > But still, the data is being converted: the final html file generated > from the db, through the views, etc., contains the entities and not the > plain html that I want to display.We''re probably going to need to see some code .
Alex Auritt
2006-Jul-18 19:07 UTC
[Rails] Re: Re: Displaying HTML pulled directly from a database
The data looks solid: no html entities. ??? James Ludlow wrote:> On 7/18/06, Alex Auritt <alexauritt@gmail.com> wrote: >> So far I''ve been manually entering the html (for testing purposes) >> through the text areas on the scaffold-generated forms. So, I take it >> this shouldn''t be a problem. >> >> But you raise a good point. It hadn''t occured to me that actual data in >> the db might have the html entities instead of the desired ''<'' >> characters. Is there an easy way for me to check what''s actually in >> the db? > > Most every database has a client program, or there are dozens of > different thrid-party options available. Check your database > documentation.-- Posted via http://www.ruby-forum.com/.
Alex Auritt
2006-Jul-18 19:57 UTC
[Rails] Re: Re: Displaying HTML pulled directly from a database
Uh-oh. I don''t know that I''m rendering at all. For these tests, I''ve just been using the scaffold-generated code. I''ve made two small modifications, which I can''t imagine would effect this. 1) I''ve tried to set the MIME-type as application/xhtml+xml (in application.rb, I''ve added: after_filter :set_charset def set_charset @headers["Content-Type"] ||= "application/xhtml+xml; charset=iso-8859-1" end ) 2) I''ve added some extra junk to the layout view, including some MathML, which displays fine. -- Anyway, the (predictable) code, controller: class ProblemsController < ApplicationController def index list render :action => ''list'' end view: <% for problem in @problems %> <tr> <% for column in Problem.content_columns %> <td><%=h problem.send(column.name) %></td> <% end %> <td><%= link_to ''Show'', :action => ''show'', :id => problem %></td> <td><%= link_to ''Edit'', :action => ''edit'', :id => problem %></td> <td><%= link_to ''Destroy'', { :action => ''destroy'', :id => problem }, :confirm => ''Are you sure?'', :post => true %></td> </tr> <% end %> -- James Ludlow wrote:> On 7/18/06, Alex Auritt <alexauritt@gmail.com> wrote: >> I check the data in the db (using the data browser on MySQL-front) and >> it looks fine -- no html entities. >> >> But still, the data is being converted: the final html file generated >> from the db, through the views, etc., contains the entities and not the >> plain html that I want to display. > > We''re probably going to need to see some code .-- Posted via http://www.ruby-forum.com/.
James Ludlow
2006-Jul-18 20:03 UTC
[Rails] Re: Re: Displaying HTML pulled directly from a database
On 7/18/06, Alex Auritt <alexauritt@gmail.com> wrote:> Uh-oh. I don''t know that I''m rendering at all. For these tests, I''ve > just been using the scaffold-generated code. I''ve made two small > modifications, which I can''t imagine would effect this.Eleo already predicted this in his first reply to your question. You''re calling h(), which is doing exactly what you''re seeing to your HTML.> <td><%=h problem.send(column.name) %></td>^^^^ -- James