Ad

How To Add ScriptTag On Shopify_api Gem?

- 1 answer

Hi Everyone,

I came across on a problem that I can't really figure out myself, It believe that all your expertise can help me through solving this error I get whenever I try to access a route to add a script. Here is my controller code: 

class HomeController < AuthenticatedController
  def index
    @products = ShopifyAPI::Product.find(:all, :params => {:product_type => "Underarmour"})
    # script = ShopifyAPI::ScriptTag.new(:all, :params => {:event => "onload", :src => "https://shopperapproved.herokuapp.com/sajs/14043.js"})
  end

  def script
     ShopifyAPI::ScriptTag.create(:event => "onload", :src => "https://shopperapproved.herokuapp.com/sajs/14043.js")
  end
end

and my route file is:

 controller :sessions do
    get 'login' => :new, :as => :login
    post 'login' => :create, :as => :authenticate
    get 'auth/shopify/callback' => :callback
    get 'logout' => :destroy, :as => :logout
  end


  root :to => 'home#index'
 match "script/",
    :to => "home#script",
    :via => :get

I want to add a script by accessing this route: on my index view:

<h3>Add your ShopperApproved site ID:</h3>
https://shopperapproved.herokuapp.com/script --> if i am going to click this link i will be redirected to HomeController#script

I hope you can help me.. 

Ad

Answer

Have you set up a seesion & token? i fnot you cant create the script in your store

https://github.com/Shopify/shopify_api

I assume you did not set up a session so you cant "connect" to your store.
Verify that you have a valide session and it will work

enter image description here

Ad
source: stackoverflow.com
Ad