Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails mountable engine and overriding another engine

I'm in the proces of converting my standard Rails app to an mountable engine. The app is comparable to a standard blogging app and i want every model, controller and view to be extendable hence my choice for a mountable engine.

One of the gems i use is Devise which is as far as i understand a sort of a mountable engine itself. It can be used inside a mountable engine as stated here.

I'm able to use it partially within my engine. Everything is working fine including some Devise controller i override like this one:

# config/routes.rb

Bbronline::Engine.routes.draw do
  devise_for :users, class_name: "Bbronline::User", module: :devise,
    controllers: { registrations: "bbronline/devise_overrides/registrations"}
    ...

# controllers/bbronline/devise_overrides/registrations_controller.rb
require_dependency "bbronline/application_controller"

module Bbronline

class DeviseOverrides::RegistrationsController < Devise::RegistrationsController

  def new_intermediair
    @user = User.new
  end
  ...

The correct view 'views/bbronline/devise_overrides/registrations/new_intermediair.html.haml' is also correctly loading as expected.

However my issue is that the views that i override without a custom controller are not properly loaded. For example the view that should the login view is located in views/bbronline/devise/sessions/new.html.haml and is not loaded. Instead the standard Devise login view gets loaded i.e. devise-2.1.0/app/views/devise/sessions/new.html.erb

Of course i could solve this problem by overriding every controller with my own controller like i did with the registrations_controller above but this seems very ugly. Is overriding every controller the way to do this? Is there a more convenient way to override views from an mountable engine from within another mountable engine?

like image 317
Harm de Wit Avatar asked Jun 29 '12 09:06

Harm de Wit


People also ask

How does a Rails engine work?

Rails looks first in the application's ( test/dummy ) app/views directory and then in the engine's app/views directory. When it can't find it, it will throw this error. The engine knows to look for blorgh/comments/_comment because the model object it is receiving is from the Blorgh::Comment class.

What is Mount in Rails?

Mounting rails are constructive items in electrical engineering and mechanical engineering projects; they are used to hold devices. A mounting rail is usually attached to a mounting panel or an enclosure profile.


1 Answers

If you don't want to adjust the config.railties_order in every app that uses your engine, just require 'devise' on top of your lib\my_engine\engine.rb file.

like image 105
wintersolutions Avatar answered Sep 18 '22 10:09

wintersolutions