hii
<%if File::exists?("../data/aritcal/#{@content.id}")%>
<div id="image_holder" class ="span-10 ">
<%= image_tag "../data/artical/#{@content.id}" %>
</div>
<%end%>
my this file exists not working
please help.
thanks
rahul
hii
<%if File::exists?("../data/aritcal/#{@content.id}")%>
<div id="image_holder" class ="span-10 ">
<%= image_tag "../data/artical/#{@content.id}" %>
</div>
<%end%>
my this file exists not working
please help.
thanks
rahul
maybe this is due to your relative path. are you sure the file is
where you think it is? are you sure the current working directory is
what you think it is?
try File::exists?("#{RAILS_ROOT}/path/to/my/file")
another thing: since you obviously left out some code and replaced it
with “…” we can’t be sure your code is correct. are you?
m sure of the path dear …
On May 5, 8:53 am, MaD [email protected] wrote:
maybe this is due to your relative path. are you sure the file is
where you think it is? are you sure the current working directory is
what you think it is?
try File::exists?(“#{RAILS_ROOT}/path/to/my/file”)
On top of that, if the current working directory is the root of the
app (which is usually is) then with a normal setup a browser won’t be
able to access that file, since its not in public.
If that’s not the case then you’re going to have to explain in what
way things don’t work. Does it work if you try from a console? is
@content what you think it is?
Fred
On 5 May 2010 07:23, Rahul M. [email protected] wrote:
<%if File::exists?(“…/data/aritcal/#{@content.id}”)%>
<%= image_tag “…/data/artical/#{@content.id}” %>
The typos probably won’t help - you spell the directory “aritcal” in
the check, and “artical” in the image tag.
The method I’ve seen for checking files is “File.exists?..” not
“File::exists?” (not sure if your way would work anyway)
And as others have said, even if the file does exist, the image tag
won’t see it because it’s not in the public path.
But let’s come back to the problem you’re trying to solve: how are you
attaching files to your content object? Maybe using a plugin like
paperclip would save you a lot of the hassle.
I experienced the same problems in a Ruby and Rails project. But when I
used
File.exist? instead of File.exists? it did work properly. Seems there is
a
problem with that or it works different.
Cheers,
Chris
On 5 May 2010 10:07, Michael P. [email protected] wrote:
The method I’ve seen for checking files is “File.exists?..” not
“File::exists?” (not sure if your way would work anyway)
In fact, “File.exist?” (without the ‘s’) is preferred according to the
API.
http://ruby-doc.org/core/classes/File.html#M002556
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs