admin管理员组文章数量:1424458
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 badges2 Answers
Reset to default 5This 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!
本文标签: javascriptHow to develop rails app for shopify with ScriptTagsStack Overflow
版权声明:本文标题:javascript - How to develop rails app for shopify with ScriptTags - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745408739a2657368.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论