9

I have a Rails project which uses an engine, and I am experiencing an issue when working in development mode.

Whenever I make some change to something in my project, the application cannot find anymore the engine's views.

 Missing template spree/api/credit_card_types/index, spree/api/base/index with {:locale=>[:es], :formats=>[:json], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee, :rabl], :versions=>[:v1]}. Searched in:
  * "/home/user/project/app/views"
  * "/home/user/.rvm/gems/ruby-2.1.0@project/bundler/gems/spree-ebda3354180a/api/app/views"

The engine's view root directory is not appearing in the search path, but I can't understand why. Any idea?

My routes.rb (note that I don't mount my engine)

require 'resque/server'

Project::Application.routes.draw do

  resources :shipping_companies

  get 'signin', to: 'signin#signin'
  get 'register', to: 'register#register'

  scope '/frontend/api', module: :api do
    # ...
  end

  namespace :frontend do
  end

  Spree::Core::Engine.add_routes do
    # ...
  end

  # Custom Admin
  Spree::Core::Engine.add_routes do
    # ...
  end

  get '/faq/' => 'pages#show', id: 'faq'
  get '/privacy/' => 'pages#show', id: 'privacy'
  get '/terms/' => 'pages#show', id: 'terms'

  mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)
  mount Resque::Server.new, :at => '/resque'
end

The controller in my engine (in app/controllers/spree/api/credit_card_types_controller.rb)

class Spree::Api::CreditCardTypesController < Spree::Api::BaseController

  def index
    @credit_card_types = SpreeDecidir::CreditCardType.all.select do |credit_card_type|
      credit_card_type.installment_plans.present?
    end.collect {|credit_card_type| SpreeDecidir::CreditCardTypePresenter.new credit_card_type}
    @amount = params[:amount].to_f if params[:amount]
  end
end

And the RABL view (at app/views/spree/api/credit_card_types/index.v1.rabl)

object false
node(:count) { @credit_card_types.count }

child(@credit_card_types => :credit_card_types) do
  extends "spree/api/credit_card_types/show"
end
finiteautomata
  • 3,753
  • 4
  • 31
  • 41

2 Answers2

1

Is RABL a dependency of the host app or the engine's? If it is the latter, remember it is the engine's responsibility to load its dependencies. Make sure to require "rabl" in it.

It seems RABL has some issues with rails engines: https://github.com/nesquena/rabl/wiki/Setup-rabl-with-rails-engines

wicz
  • 2,315
  • 12
  • 13
0

Without having more of your code to base my answer off of, I would guess that you are missing one of two things:

1) You are missing views (i.e. api/app/views/index.html.erb)

2) You are missing redirects to your views. Somewhere, something is trying to render an action and it can't find the corresponding view template (hence the missing template error).

If you want a more specific response I'd recommend posting more of your code (if you can't post your code consider posting a sanitized version or create a simple rendition of what you are doing).

jkeuhlen
  • 4,401
  • 23
  • 36