Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Not reloading engine's view path in development

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
like image 870
finiteautomata Avatar asked Jul 01 '14 19:07

finiteautomata


1 Answers

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

like image 171
wicz Avatar answered Nov 07 '22 20:11

wicz