This is probably a blantant newbie question, but I haven''t been able to figure it out. I let users upload a picture, which I put into a folder (headshots) in the public folder. Now I want to display the picture via an image tag. But I can''t figure out how to code the URL. I tried <img src="<%= @RAILS_ROOT %>public/headshots/<%= @profile.id % >.jpg" height="200" /> But the image didn''t load. This is in development using Webrick. Ron Davis I''ve got images in my head and I want to get them into my camera and portfolio. http://photo.reactuate.com/ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Jul 8, 2005, at 1:23 PM, Ron Davis wrote:> This is probably a blantant newbie question, but I haven''t been > able to figure it out. > > I let users upload a picture, which I put into a folder (headshots) > in the public folder. > > Now I want to display the picture via an image tag. But I can''t > figure out how to code the URL. > > I tried > > <img src="<%= @RAILS_ROOT %>public/headshots/<%= @profile.id % > >.jpg" height="200" /> >RAILS_ROOT (not @RAILS_ROOT) is the variable you''re trying to use... however, it isn''t the one you want. RAILS_ROOT will give you the private path to your rails app within the system (e.g. c:\ruby\rails \my_project\ on Windows or /code/my_project/ on Unix). That is very different from the public URL that you''ll want others to access your public folder from--actually, others can access anything in the RAILS_ROOT/public folder on your system as simply "/" on their browser''s URL. So, to get what you''re after: <img src="/headshots/<%= @profile.id %>.jpg" /> Or you can use the image tag: <%= image_tag "/headshots/#{@profile.id}.jpg", :height => 200 %> Duane Johnson (canadaduane)
I''m just chiming in here with a question or two... To avoid having to use absolute URLs in image/link tags, is there a RAILS_BASE_URL or equivalent? Does using image_tag avoid absolute URLs? jason Duane Johnson wrote:> So, to get what you''re after: > > <img src="/headshots/<%= @profile.id %>.jpg" /> > > Or you can use the image tag: > <%= image_tag "/headshots/#{@profile.id}.jpg", :height => 200 %>
Why are absolute URLs bad? On 7/8/05, Jason Hines <jason-PCkqsL0hywUS+FvcfC7Uqw@public.gmane.org> wrote:> > I''m just chiming in here with a question or two... > > To avoid having to use absolute URLs in image/link tags, is there a > RAILS_BASE_URL or equivalent? > > Does using image_tag avoid absolute URLs? > > jason > > Duane Johnson wrote: > > So, to get what you''re after: > > > > <img src="/headshots/<%= @profile.id %>.jpg" /> > > > > Or you can use the image tag: > > <%= image_tag "/headshots/#{@profile.id}.jpg", :height => 200 %> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Jul 9, 2005, at 1:40 PM, Joe Van Dyk wrote:> Why are absolute URLs bad? >It seems that the question relates to the problem of, for example, developing a site on http://my.devsite.com/~project/ and then moving it up to production at http://my.productionsite.com/. Hard-coded image URLs won''t transfer very easily. Perhaps the original question has to do with the "hard-coded" aspect rather than the "absolute" aspect of image_tag. I think the image_tag uses hard-coded URLs. Duane Johnson (canadaduane)