Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   File.open of HTML file removes code (http://www.velocityreviews.com/forums/t867051-file-open-of-html-file-removes-code.html)

Scott Elwood 04-27-2011 06:01 AM

File.open of HTML file removes code
 
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/.


Nikita Baksalyar 04-27-2011 06:52 AM

Re: File.open of HTML file removes code
 
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/.


Brian Candler 04-27-2011 07:49 AM

Re: File.open of HTML file removes code
 
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/.


Scott Elwood 04-27-2011 06:57 PM

Re: File.open of HTML file removes code
 
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/.


7stud -- 04-28-2011 12:39 AM

Re: File.open of HTML file removes code
 
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/.


Scott Elwood 04-28-2011 06:14 AM

Re: File.open of HTML file removes code
 
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/.



All times are GMT. The time now is 02:57 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.