Search code examples
ruby-on-railsspree

Rails API Versioning Spree + rabl


I've an e-commerce app which built using Spree, now i need to create a new version of the API for a certain controller and here's what i did

  • created a new controller in /api/v2/x_controller.rb
  • made an action index
  • add route for my controller in routes.rb
  • made a rabl file ( index.v2.rabl )

when i try to access the api my request hit the action but i keep getting error

ActionView::MissingTemplate (Missing template spree/api/v2/x/index)

i there any missing configuration i should do ?!


Solution

  • Your RABL view should be under

    app/views/api/v2/x/index.rabl
    

    There is a naming convention for views in Rails. Typically, the views share their name with the associated controller action. For example, the index controller action of the articles_controller.rb will use the index.html.erb view file in the app/views/articles directory. The complete HTML returned to the client is composed of a combination of this ERB file, a layout template that wraps it, and all the partials that the view may reference.