views:

25

answers:

1

Hi Everyone,

I am using a Gem to communicate with FreeagentCentral via their API. I have the following code to display a link to the relevant freeagent project:

<%= link_to "#{image_tag('/images/icons/Spinning Beach Ball.png')} Freeagent Project", "#{Freeagent::Base.site.to_s + Freeagent::Project.element_path(@kase.freeagent_id).gsub(/\A\//, '').gsub!(/.xml/,'')}" if @kase.freeagent_id %>

The problem - There is a / omitted from the URL which makes the url like this:

https://XXXXX.freeagentcentral.comprojects/12345

where it should be:

https://XXXXX.freeagentcentral.com/projects/12345

This may be simple, but to me - it's driving me crazy!

Thanks,

Danny

+1  A: 

I'm assuming that Freeagent::Base.site is retuning 'https://XXXXX.freeagentcentral.com'. In which case, you just need to add the / into your string between the site and project parts. Try the following:

<%= link_to "#{image_tag('/images/icons/Spinning Beach Ball.png')} Freeagent Project", 
  "#{Freeagent::Base.site}/#{Freeagent::Project.element_path(@kase.freeagent_id).gsub(/\A\//, '').gsub!(/.xml/,'')}" if @kase.freeagent_id %>

Edit:

Looking at this more closely, gsub(/\A\//, '') is removing a / from the start of the string returned by Freeagent::Project.element_path(@kase.freeagent_id). Assuming that element_path does actually return a string with a leading /, the better answer would be to remove the first gsub call:

<%= link_to "#{image_tag('/images/icons/Spinning Beach Ball.png')} Freeagent Project", 
  "#{Freeagent::Base.site}#{Freeagent::Project.element_path(@kase.freeagent_id).gsub!(/.xml/,'')}" if @kase.freeagent_id %>
Phil Ross
Excellent thanks! For some reason I thought the / should go further into the string. Thanks again!
dannymcc