javascript - How to develop rails app for shopify with ScriptTags - Stack Overflow

I have a shopify app deployed in Heroku, developed in Rails. I need call a javascript function from an

I have a shopify app deployed in Heroku, developed in Rails. I need call a javascript function from any shopify store's frontend. I've read this article ( ), but I don't understand it...

Where do I have to put this code:

HTTP POST 

  <?xml version="1.0" encoding="UTF-8"?>
  <script-tag>
    <src>.js</src>
    <event>onload</event>
  </script-tag>

What should be the src tag (for my deployed rails app), and where should I put the javascript call function?

I have a shopify app deployed in Heroku, developed in Rails. I need call a javascript function from any shopify store's frontend. I've read this article ( http://www.shopify./technology/3033852-shopify-api-update-scripttags-javascript-insertion ), but I don't understand it...

Where do I have to put this code:

HTTP POST http://their-shop.myshopify./admin/scripttags

  <?xml version="1.0" encoding="UTF-8"?>
  <script-tag>
    <src>http://example./your-awesome-script.js</src>
    <event>onload</event>
  </script-tag>

What should be the src tag (for my deployed rails app), and where should I put the javascript call function?

Share Improve this question edited Aug 13, 2012 at 15:08 kungfucsiga asked Aug 13, 2012 at 14:22 kungfucsigakungfucsiga 3391 gold badge4 silver badges13 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

This might help.

Shopify Rails App

You simply need to authenticate user and then you need to take the token generated from Shopify and save it in your Database. Later on just do:

ShopifyAPI::Base.site = token

and then install the script using:

s = ShopifyAPI::ScriptTag.create(:events => "onload",:src => "your javascript url")

and you are done!

This is what I did to get it working:

In the sessions_controller.rb file located in app > controllers

After this

def show
  if response = request.env['omniauth.auth']
    sess = ShopifyAPI::Session.new(params[:shop], response[:credentials][:token])
    session[:shopify] = sess

I added

ShopifyAPI::Base.activate_session(sess)
ShopifyAPI::ScriptTag.create(:event => "onload", :src => "https://ajax.googleapis./ajax/libs/jquery/1.7.2/jquery.min.js")

You need to replace https://ajax.googleapis./ajax/libs/jquery/1.7.2/jquery.min.js in the code above with your absolute js file path.

Then in the omniauth.rb file located in config > initializers make sure you add write_script_tags to the scope i.e.

:scope => 'write_script_tags',

and you might also need to restart your rails server and re-install the app so that these privileges have been granted. That should do the trick!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745408740a4626432.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信