Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > File.open of HTML file removes code

Reply
Thread Tools

File.open of HTML file removes code

 
 
Scott Elwood
Guest
Posts: n/a
 
      04-27-2011
Hey there,

I am trying to edit an erb file in ruby, however when I do:

file.open("index.erb")

It displays the information, but removes the Doctype, html, body, and
head tags.

Is there any way to read the entire contents of the .erb file?

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Nikita Baksalyar
Guest
Posts: n/a
 
      04-27-2011
Hello,

Please try to run this commands in your OS command prompt:

For Windows:

type index.erb

For Linux/Mac OS X:

cat index.erb

And then:

$ irb
irb(main):001:0> File.open('index.erb').read

Then compare system output with Ruby's output - if they have no
differences - the problem is somewhere in your code. In that case please
post your code to www.pastebin.com and give a link there.

Good luck.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      04-27-2011
Scott Elwood wrote in post #995260:
> Hey there,
>
> I am trying to edit an erb file in ruby, however when I do:
>
> file.open("index.erb")
>
> It displays the information, but removes the Doctype, html, body, and
> head tags.
>
> Is there any way to read the entire contents of the .erb file?


File.open("...") just opens the file and returns an open File object,
but it doesn't read it until you ask it to.

Try:

File.open("index.erb") do |file|
file.each_line do |line|
puts line
end
end

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Scott Elwood
Guest
Posts: n/a
 
      04-27-2011
Thanks to both of you!

I checked both of the code you guys suggested and it worked fine.
However there is still a problem.

I am developing an application for a ruby class I am in, and I would
like to edit some of that .erb file in an HTML textarea. I am using
Ruby/Sinatra, and here is what happens:

If I print the data into a <div>, it will show everything including the
doctype, body, etc.

Yet when I do this:

<textarea cols="93" rows="32" name="contents">
<% File.open("views/layoutAdmin.erb") do |file| %>
<% file.each_line do |line| %>
<%= line %>
<% end %>
<% end %>
</textarea>

The textarea will take away all of the aforementioned tags. Like I said
before, if I replace the <textarea> tags with <div> tags, it works fine,
but I of course can't edit that content.

Is there some reason why textareas do not display this data?

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
7stud --
Guest
Posts: n/a
 
      04-28-2011
Scott Elwood wrote in post #995373:
> Thanks to both of you!
>
> I checked both of the code you guys suggested and it worked fine.
> However there is still a problem.
>
> I am developing an application for a ruby class I am in, and I would
> like to edit some of that .erb file in an HTML textarea.


You need to post that .erb file. Or, even better, create the most
minimal .erb file you can that will still exhibit your problem.


>
> If I print the data into a <div>,
>


Huh? What data? What <div>?

>
> Is there some reason why textareas do not display this data?
>


Huh? I thought we were talking about an .erb file? erb files don't
display anything.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Scott Elwood
Guest
Posts: n/a
 
      04-28-2011
Thanks again for the comment, it led me to test some stuff out and found
it was TinyMCE javascript plugin that was removing the header and such.
I tried testing if that was the case earlier but a refresh of the page
didn't refresh the code, I had to actually reload the page for it to
reset.

Sorry for the confusion, this is a great forum

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic element creation removes HTML from innerHTML bgold12 Javascript 7 09-02-2008 03:56 AM
[OT] Microsoft's AntiSpyware Tool removes Internet Explorer T-Bone MCSE 11 01-19-2005 08:18 PM
removes a single page from the output cache Egon Berger ASP .Net 0 11-02-2004 02:38 PM
VS.NET designer removes runat='server' attribute in <title> =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?= ASP .Net 1 07-15-2004 03:24 AM
VS.NET removes "Runat=Server" without asking??? Ronald Colijn ASP .Net 1 11-27-2003 09:01 AM



Advertisments