0

Ok so i have a campaign javascript that i need to get for a site. The site is under ssl and the campaign is not so the browser blocks the request

So to work around i am doing the request via the application_controller

before_filter :get_campaign 

def get_campaign
  uri = URI.parse("http://us1.campaign-archive1.com/generate-js/?u=2f77d2f8c77398c0b064223ba&fid=1&show=3")
  begin
    @campaign = Net::HTTP.get_response(uri).body
  end
end

and in the view i do

      %script{:language => "javascript", :type => "text/javascript"}
        = @campaign.try(:html_safe)

because the @campaign is a document.write string...but for some reason its not writing....am i missing something or is there a better way to achieve this

UPDATE

After looking at the console in chrome i see this error Uncaught SyntaxError: Unexpected token <

Here is my generated code

  <script language='javascript' type='text/javascript'>
                  document.write("<div class=\"display_archive\"><div class=\"campaign\">08\/29\/2012 - <a href=\"http:\/\/us1.campaign-archive1.com\/?u=2f77d2f8c77398c0b064223ba&id=4c4d33ed6f\" title=\"Ten Fun Facts and Figures from Gen Con Indy 2012\" target=\"_blank\">Ten Fun Facts and Figures from Gen Con Indy 2012<\/a><\/div><\/div>");
                  <br>
                  <div class='display_archive'></div>
                  <div class='campaign'>
                    Select
                    <a href='http://eepurl.com/jkmGT' target='_blank'>HERE</a>
                    to sign up for our newsletter! 
                  </div>
                </script>
2
  • first check if @campaign is empty or not. Commented Nov 10, 2012 at 4:50
  • @campaign is not empty...i just noticed an error in the console..i will update my question Commented Nov 10, 2012 at 4:58

2 Answers 2

1

The Javascript fragment you're downloading contains characters which can't be used unescaped and you're preventing the escaping from happening. Usually one wraps this sort of stuff in CDATA tags. The haml javascript filter does this for you if CDATA support is turned on (it is by default for XHTML):

:javascript
  #{@campaign}
Sign up to request clarification or add additional context in comments.

Comments

0

Why do you have HTML inside a script tag? I'm pretty sure that's what the problem is, you should delete everything from and including br in your @campaign.

@campaign.gsub!(/<br.*/, "")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.