File.open of HTML file removes code

S

Scott Elwood

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?
 
N

Nikita Baksalyar

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. :)
 
B

Brian Candler

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
 
S

Scott Elwood

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?
 
7

7stud --

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 said:
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.
 
S

Scott Elwood

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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top