开发者

Rails / omitted from link_to?

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 Proje开发者_开发问答ct", "#{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


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 %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜