# Not solved - problem in accesing file

**URL:** <https://www.ruby-forum.com/t/not-solved-problem-in-accesing-file/181393>\
**Category:** Rails\
**Created:** [January 11, 2010, 12:46pm UTC](https://www.ruby-forum.com/t/not-solved-problem-in-accesing-file/181393 "2010-01-11T12:46:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [January 11, 2010, 12:46pm UTC](https://www.ruby-forum.com/t/not-solved-problem-in-accesing-file/181393/1 "2010-01-11T12:46:51Z")

</div>

Dear all,

I have a question which is driving me crazy

Kindly look the below code

In my public folder

public/Server\_exe/ChatHistory/2010-01-10/2010-01-10\1~Vs~2\1~Vs~2.html  
=\> this is my live chat file path

for the above chat file images are in the following path

public/Server\_exe/ChatHistory/2010-01-10/1~Vs~2/ScreenCapture/2120100109101048121.jpg  
=\> this image is shown in the chat file

\<%= link\_to image\_tag(“backup.png”,:title =\> “view  
chat”),"/Server\_exe/#{log.file\_path}", :popup =\> true %\>

when clicking on the above link i show the live(the files which are not  
moved to the archive location)chat files on a browser window these chat  
files are located in our rails applications public directory.this works  
just fine.that chat file can contain images with it.and this method  
properly opens a browser window and shows the chat file with images.in  
this case i don get any problem since it shows the chat file as it as  
they are.

But when i move these chat files to the archived location i wil be  
running into the problem

Archive location is D:/temp

so these files wiil be moved to the above location when archive  
functionlity is taking place.

Archived folder structure

D:\Temp\ChatHistory\2010-01-10\2010-01-10\1~Vs~2\1~Vs~2.html =\> this is  
my archived chat file path

D:\Temp\ChatHistory\2010-01-10\1~Vs~2\ScreenCapture\2120100109101048121.jpg  
=\> this image is shown in the chat file

So to view the archived chat file from the archive location i use method  
like below…

\<%= link\_to image\_tag(“backup.png”,:title =\> “view chat”),{:action =\>  
“open\_file”,:file\_path =\> @file\_path},{:target =\> ‘\_new’} %\>

def open\_live\_file  
#--------------  
@backup = Backup.find(:first)

```
unless @backup.nil? and params[:file_path].nil?

  file_path = params[:file_path]

  if File.exists?("#{file_path}")

    render :file => "#{file_path}", :layout => false

  end

end

```

end

when clicking on the above link it opens the html file on a browser  
window but it has not shown the images in the html file.  
In the archived location i place the html files and corresponding images  
in the same folder only…  
In this case what is the way to display the html file with images with  
it ??

And also to show live chat i just changed the code like below to test  
the render functionality

\<%= link\_to image\_tag(“backup.png”,:title =\> “view chat”),{:action =\>  
“open\_live\_file”,:file\_path =\> @file\_path},{:target =\> ‘\_new’} %\>

def open\_live\_file  
#--------------  
@backup = ChathistoryBackup.find(:first)

```
unless @backup.nil? and params[:file_path].nil?

  file_path = params[:file_path]

  if File.exists?("#{file_path}")

    render :file => "#{file_path}", :layout => false

  end

end

```

end

after the above changes it has opened the live chat file form the  
public folder but it has not shown the images .  
why this is so?? that images are only in the public folder then why it  
has not shown the chat file images when i used the above code…  
What i m missing or what i m doing wrong in my code ?  
Kindly let me know your Views on this…

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [January 11, 2010, 1:23pm UTC](https://www.ruby-forum.com/t/not-solved-problem-in-accesing-file/181393/2 "2010-01-11T13:23:50Z")

</div>

2010/1/11 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> files are located in our rails applications public directory.this works  
> so these files wiil be moved to the above location when archive  
> So to view the archived chat file from the archive location i use method
> 
> Â end  
> the render functionality  
> Â Â Â file\_path = params[:file\_path]
> 
> after the above changes it has opened the live chat file form Â the  
> public folder but it has not shown the images .  
> why this is so?? that images are only in the public folder then why it  
> has not shown the chat file images when i used the above code…  
> What i m missing or what i m doing wrong in my code ?  
> Kindly let me know your Views on this…

Your question is too complex for me to fully understand without  
spending a lot of time examining it, however your web server will not  
be able to access files in d:/temp, if this is what you are trying to  
do (unless you have the server setup in a strange way). Generally all  
static files that wish to serve should stay under the public folder.

If this does not help have a look at the html that is not working and  
see what is wrong with it.

If that still does not help simplify the problem to one that is more  
easily understood and re-post.

Colin

Colin
