Topic: inserting images into a blog

Hi everyone
Does anyone have any idea how i could insert images into blog text? Ideally i would like to add the <img> tag into my blog text in order to insert the images, but i have been having problems with absolute and relative paths.

Can anyone advice please?

Re: inserting images into a blog

On my blog, I use Textile and so I use this syntax: http://rpc.textpattern.com/help/?item=image

But what's exactly your problem with absolute and relative paths?

My homepage: http://www.komendera.com/
Working at: http://www.abloom.at/
My blog: soaked and soaped http://soakedandsoaped.com/

Re: inserting images into a blog

Thanks for your reply Dieter,

my problem was this, i had paths hard coded to pictures in blog entries in my test system. I recently went live and all my links were broken as the paths had changed. I thought there must be a better way of doing this. Someway i link to these image within my blog text that would be more robust, something more like "image_tag"

Re: inserting images into a blog

In the config/environments/ folder you can see there's a separate file for each envirnoment (development, test, and production). You can set configurations here and have them vary depending upon the environment.

# in an environment file
IMAGE_PATH_PREFIX = '/my_images/'

You can then create your own image helper:

# in application_helper.rb
def prefixed_image_tag(source, options = {})
  source = IMAGE_PATH_PREFIX + source # add some conditional checking here to only do this on relative paths
  image_tag(source, options)
end

Hope that helps.

Railscasts - Free Ruby on Rails Screencasts

Re: inserting images into a blog

Thanks ryanb, i didnt know that, but i am not sure it helps in my situation. I want to be able to add a blog post (string) directly to the database that will include all the information as to where my images are to be positioned within it, if i add ruby code to the string it wont ever get processed.

Re: inserting images into a blog

You may want to use relative paths in your blog post (just give the name of the file for example) then parse this to insert the full path using the technique I gave above. See this thread on a way to parse the blog post.

Railscasts - Free Ruby on Rails Screencasts

Re: inserting images into a blog

Great! thanks very much!