Rails_root

Hey,

I’m using the attachment_fu plugin to upload images on the file system.
To retrieve them I’m using:

image = “/home/rajeev/Desktop/logo/logo/public#{icon.public_filename}”
which is the same as:

“/home/rajeev/Desktop/logo/logo/public/icons/0000/0005/green_nature_on_white.jpg”

Have can i do this in a shorter way by using RAILS_ROOT? I have tried
this but no success.

Would appreciate any help.

Thanks

Raj

On Oct 24, 2007, at 11:14 AM, Rajeev K. wrote:

green_nature_on_white.jpg"

Have can i do this in a shorter way by using RAILS_ROOT? I have tried
this but no success.

Would appreciate any help.

Thanks

Raj

Take your pick:

image = File.join(RAILS_ROOT, “public#{icon.public_filename}”)
image = File.expand_path(‘public’ + icon.public_filename, RAILS_ROOT)
image = File.join(RAILS_ROOT, ‘public’, icon.public_filename)

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Have can i do this in a shorter way by using RAILS_ROOT? I have tried
this but no success.

just general fyi, but basically the RAILS_ROOT constant is a String
object.
you can use it any way you’d use a string

RAILS_ROOT + “/some/string/”
RAILS_ROOT.split(’/’)
RAILS_ROOT.is_a?(String) # true

hope this helps.
:slight_smile:

Hey,

Thanks for that it works perfect. Just got one question. When I run all
3 lines in the console i get:

image = File.join(RAILS_ROOT, ‘public’, icon.public_filename)
“script/…/config/…/config/…/public/icons/0000/0005/green_nature_on_white.jpg”

image = File.expand_path(‘public’ + icon.public_filename, RAILS_ROOT)
“/home/rajeev/Desktop/logo/logo/public/icons/0000/0005/green_nature_on_white.jpg”

image = File.join(RAILS_ROOT, “public#{icon.public_filename}”)
“script/…/config/…/config/…/public/icons/0000/0005/green_nature_on_white.jpg”

Although they all work I don’t understand what the script/…/config…
bit means?

Cheers

On Oct 25, 2007, at 4:59 AM, Rajeev K. wrote:

image = File.expand_path(‘public’ + icon.public_filename, RAILS_ROOT)

Cheers

It means that RAILS_ROOT == ‘script/…/config/…/config/…’
It also implies that the current directory is almost certainly the
same as RAILS_ROOT because ‘…’ means the parent directory so any
‘foo/…’ means the foo subdirectory’s parrent – the current
directory. You can generally remove such constructs (there are some
oddities that can happen with symbolic links that you can likely
ignore in this case).

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs