[HELP]How To Add Script Tag using shopify_api gem?

Highlighted
Shopify Partner
2 0 0

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
  
  match ':controller(/:action(/:id))', :via => :get
  root :to => 'home#index'
  get 'script' => 'home#addscript'

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 home#script

I hope you can help me.. 

0 Likes
Highlighted
New Member
2 0 0

 

 

Verbigratia:

     

   tag ||= ShopifyAPI::ScriptTag.new
   tag.src='https://your.server.net/assets/storefront/my-customizer-v2.js'
   tag.event = 'onload'
   tag.save!

Check with:

ShopifyAPI::ScriptTag.all

 

 

 

 

0 Likes