How to develop rails app for shopify with ScriptTags

只愿长相守 提交于 2019-12-06 13:42:35

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.com/ajax/libs/jquery/1.7.2/jquery.min.js")

You need to replace https://ajax.googleapis.com/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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!