gerry.jenkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-10 20:50 UTC
Link to local files
I have a small rails system I am building. Part of the code allow uploading files in to RailsRoot/public/files folder I am running this system is several places that have different domain and folder combinations. cases: 1) domain1.com/folder_a # where folder_a is a symbolic link from Apache document root to the public folder of rails app 2) domain2.com/folder_b/public # where folder_b is the root of the rails app directly in the Apache document root 3) domain3.com # where I have set up a virtual host to point directly to the rails application root If I have uploaded a file called test.doc, I would like to create a link from my rhtml template to the file that works where in which ever domain setup variation you see above. How can I use link_to or something to create the following correct links for href= attribute in my link for each case above for each case the correct Absolute links for file.doc should be: 1) domain1.com/folder_a/files/test.doc 2) domain2.com/folder_b/public/files/test.doc 3) domain3.com/files/test.doc of course I can''t use relative links for in the case of domain setup 1) link_to ("your file","files/test.doc") just goes to domain1.com.folder_a/controller/actions/files/test.doc link_to ("your file","/files/test.doc") just goes to domain1.com/files/ test.doc << back to domain base ignoring folder_a --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gerry.jenkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-10 23:16 UTC
Re: Link to local files
Well, after some experimenting, I have a cluge to find the URL path up to the Rails Base: s = "#{url_for(:controller => ''xxx'')}" # create url to fake controller to just to get full path @base_url = @s.match(/(.*)\/xxx/)[1] # then find the part of the path up to /xxx @base_url now has the correct path as the app moves to different domain setups. I hate this kind of code. Someone have a clean way? On Apr 10, 1:50 pm, "gerry.jenk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <gerry.jenk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a small rails system I am building. Part of the code allow > uploading files in to > > RailsRoot/public/files folder > > I am running this system is several places that have different domain > and folder combinations. > > cases: > > 1) domain1.com/folder_a # where folder_a is a symboliclinkfrom > Apache document root to the public folder of rails app > 2) domain2.com/folder_b/public # where folder_b is the root of the > rails app directly in the Apache document root > 3) domain3.com # where I have set up a virtual host to point directly > to the rails application root > > If I have uploaded afilecalled test.doc, I would like to create alinkfrom my rhtml template to thefilethat works where in which ever > domain setup variation you see above. > > How can I use link_to or something to create the following correct > links for href= attribute in mylinkfor each case above > > for each case the correct Absolute links forfile.doc should be: > > 1) domain1.com/folder_a/files/test.doc > 2) domain2.com/folder_b/public/files/test.doc > 3) domain3.com/files/test.doc > > of course I can''t use relative links > > for in the case of domain setup 1) > > link_to ("yourfile","files/test.doc") just goes to > domain1.com.folder_a/controller/actions/files/test.doc > link_to ("yourfile","/files/test.doc") just goes to domain1.com/files/ > test.doc << back to domain base ignoring folder_a--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gerry.jenkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-10 23:24 UTC
Re: Link to local files (one way to do it)
Well, after some experimenting, I have a cluge to find the URL path up to the Rails Base: s = "#{url_for(:controller => ''xxx'')}" # create url to fake controller to just to get full path @base_url = s.match(/(.*)\/xxx/)[1] # then find the part of the path up to /xxx # @base_url now has the correct path as the app moves to different now I can use something like <%= link_to("your file","#{@base_url}/files/#{@filename}") %> domain setups. I hate this kind of code. Someone have a clean way? On Apr 10, 1:50 pm, "gerry.jenk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <gerry.jenk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a small rails system I am building. Part of the code allow > uploading files in to > > RailsRoot/public/files folder > > I am running this system is several places that have different domain > and folder combinations. > > cases: > > 1) domain1.com/folder_a # where folder_a is a symbolic link from > Apache document root to the public folder of rails app > 2) domain2.com/folder_b/public # where folder_b is the root of the > rails app directly in the Apache document root > 3) domain3.com # where I have set up a virtual host to point directly > to the rails application root > > If I have uploaded a file called test.doc, I would like to create a > link from my rhtml template to the file that works where in which ever > domain setup variation you see above. > > How can I use link_to or something to create the following correct > links for href= attribute in my link for each case above > > for each case the correct Absolute links for file.doc should be: > > 1) domain1.com/folder_a/files/test.doc > 2) domain2.com/folder_b/public/files/test.doc > 3) domain3.com/files/test.doc > > of course I can''t use relative links > > for in the case of domain setup 1) > > link_to ("your file","files/test.doc") just goes to > domain1.com.folder_a/controller/actions/files/test.doc > link_to ("your file","/files/test.doc") just goes to domain1.com/files/ > test.doc << back to domain base ignoring folder_a--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gerry.jenkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-11 02:45 UTC
Re: Link to local files
Found simple way of solving the problem by examining how image_tag works: use request.relative_url_root: if your URL to your rails root is www.domain.com/path1/path2/ then request.relative_url_root will return /path1/path2 By combining this with link_to or image_tag, you can create links that will work with any configuration of server url path to your rails app: example: <%= link_to("your file2", request.relative_url_root+''/ files/''+@filename) %> <%= image_tag(request.relative_url_root+''/files/''+@filename)%> On Apr 10, 1:50 pm, "gerry.jenk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <gerry.jenk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a small rails system I am building. Part of the code allow > uploading files in to > > RailsRoot/public/files folder > > I am running this system is several places that have different domain > and folder combinations. > > cases: > > 1) domain1.com/folder_a # where folder_a is a symbolic link from > Apache document root to the public folder of rails app > 2) domain2.com/folder_b/public # where folder_b is the root of the > rails app directly in the Apache document root > 3) domain3.com # where I have set up a virtual host to point directly > to the rails application root > > If I have uploaded a file called test.doc, I would like to create a > link from my rhtml template to the file that works where in which ever > domain setup variation you see above. > > How can I use link_to or something to create the following correct > links for href= attribute in my link for each case above > > for each case the correct Absolute links for file.doc should be: > > 1) domain1.com/folder_a/files/test.doc > 2) domain2.com/folder_b/public/files/test.doc > 3) domain3.com/files/test.doc > > of course I can''t use relative links > > for in the case of domain setup 1) > > link_to ("your file","files/test.doc") just goes to > domain1.com.folder_a/controller/actions/files/test.doc > link_to ("your file","/files/test.doc") just goes to domain1.com/files/ > test.doc << back to domain base ignoring folder_a--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---