skip to Main Content

Currently I am learning to create a Shopify custom app. I am working on metafields. A metafield can be created by

@metafield = ShopifyAPI::Metafield.new()

In form view, I use

<%= bootstrap_form_for @metafield do |f| %>
<% end %>

The form requires me to define shopify_api_metafields_path etc.

Is there a way to define prefix shopify_api to my routes resources :metafields without adding ShopifyApi:: module to my controller?

2

Answers


  1. Chosen as BEST ANSWER

    I come up with solution by defining a model Metafield which inherit from ShopifyAPI::Metafield and then, I define @metafield = Metafield.new instead of @metafield = ShopifyAPI::Metafield.new

    By this way, it will be easier to manage later and it allow us to synchronize data table as well.


  2. You could try:

    resources :shopify_api_metafields, controller: :metafields
    

    Which will give you:

        shopify_api_metafields GET    /shopify_api_metafields(.:format)               metafields#index
                               POST   /shopify_api_metafields(.:format)               metafields#create
     new_shopify_api_metafield GET    /shopify_api_metafields/new(.:format)           metafields#new
    edit_shopify_api_metafield GET    /shopify_api_metafields/:id/edit(.:format)      metafields#edit
         shopify_api_metafield GET    /shopify_api_metafields/:id(.:format)           metafields#show
                               PATCH  /shopify_api_metafields/:id(.:format)           metafields#update
                               PUT    /shopify_api_metafields/:id(.:format)           metafields#update
                               DELETE /shopify_api_metafields/:id(.:format)           metafields#destroy
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search