Rails 3.1.1 - with mounted engines, is it possible to access the parent assets of applications, by default?

This is more for experimentation - I know that I can do it with --full, but I wanted the namespacing functions in the application to avoid conflicts

The idea is to have a main application that handles authentication, common elements, admin screens, etc. Then create mechanisms to add additional features, such as

  • crm
  • cms
  • The blog
  • wiki
  • forum
  • etc.

These engines I can choose and choose as I need for any application that I create. Is it possible?

Can I use both the --mountable and --full options?

Experimenting - there would be some kind of problem if I used the full add rspec option and then just added

rails plugin new plugin_name --skip-test-unit --full --dummy-path=spec/dummy 

and in lib \ plugin_name \ engine.rb

 module PluginName class Engine < Rails::Engine # this is added by rails when an engine is mountable # to isolate the plugin and prevent name clashes isolate_namespace PluginName # one of the additions to make rspec work from command line for the plugin config.generators do |g| g.test_framework :rspec, :view_specs => false end end end 

I already created both --full and -mountable engine, and finally rspec works for those who read, there are some great articles (see below), but wondered about the wider impact of this on the solution I'm trying to create

I am still playing with this and will post my findings.
Any help / discussion would be appreciated by weight.

note

  • Why I want to do this - create once many times ...
  • I would never want a non-tech / client to add “plugins / engines” - this is just to entertain point 1.

The problems that I have ...

  • Starting the server in a top-level application. Only when accessing content from the mechanism (I see error messages) I have a routing problem (root_path is undefined or there are no routing paths) - the layout of the parent application is displayed, I can see it in the extracted source Error. Progress, but no cigars!

useful links

+6
source share
2 answers

I managed to complete this work with the following steps:

  • In my parent application, I mounted the engine in route.rb

     mount PluginName::Engine => '/plugin_name' 

    I just deleted it.

  • Created the application controller that Ryan Bigg talked about below.

     class PluginName::ApplicationController < ApplicationController ... end 
  • As I wanted all the names to be distributed when creating controllers, models, tests, so you need to essentially comment on isolate_namespace PluginName lib \ plugin_name \ engine.rb when I wanted the stone to be run in the parent application.

    This is not an ideal solution. from the top of my head, I could use something like:

     isolate_namespace PluginName if %w[development testing].include?(Rails.env) 

    but you will need to check how practical it is.

Kudos to Ryan for helping me find many thanks

Alternatively, you can do the same with the -mountable switch version, and all you have to do is just one more step in your config / routes.rb configurations.

 PluginName::Engine.routes.draw do 

from

 Rails.application.routes.draw do 
+2
source

Yes, you can reference the parent assets of the application by simply referring to them in your application, as usual:

  <%= stylesheet_link_tag "application %> 

Although, I’m not sure why you would like to do this, because ...

I will answer your first question with the answer to your second question.

To use the application layout, you will need to modify the ApplicationController in the engine (which is in the namespace) and inherit it from the ApplicationController in the engine.

Then, the controllers for the engine will be installed using the layout provided by the engine. I do this in my engine, forem .

One fine day, this will be described in the Engine Manual , which is currently being written.

+1
source

Source: https://habr.com/ru/post/899031/


All Articles