Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mount in Rails engine #558

Open
paxer opened this issue Feb 8, 2018 · 4 comments
Open

Mount in Rails engine #558

paxer opened this issue Feb 8, 2018 · 4 comments

Comments

@paxer
Copy link

paxer commented Feb 8, 2018

Hi,

I want to mount Ember frontend in the Rails engine, I am following the steps and since it is Rails engine, I've added require_dependency 'ember_cli' to the initializer, however when I try to start the engine's parent app - I've got

undefined method `mount_ember_app' for #<ActionDispatch::Routing::Mapper:0x00007f8aaa9605c8>

any tips how to make it work?

Thanks

Which operating system and version is the project developed on?
macOS

Which version of ruby is the project developed on?
2.5.0

Which version of npm is the project developed on?
5.6.0

Which version of ember-cli is the project developed on?
2.18.2

What is the rails version?
5.1.4

What is the ember-cli-rails version (from Gemfile)?
0.10.0

What is the ember-cli-rails-addon version (from package.json)?
0.10.0

Is your application server multi-threaded
(such as puma and unicorn) or is it multi-process (such as thin and webrick)?

webrick

What are the contents of config/initializers/ember.rb?

require_dependency 'ember_cli'

EmberCli.configure do |c|
  c.app :frontend
end

What are the contents of the Rails' view that renders the Ember application?
blank

How are the EmberCLI-related routes defined?

MyEngine::Engine.routes.draw do
  mount_ember_app :frontend, to: '/'
end

How is the application deployed?

@paxer paxer changed the title Mount to Rails engine Mount in Rails engine Feb 8, 2018
@paxer
Copy link
Author

paxer commented Feb 8, 2018

ok, I've removed require_dependency 'ember_cli' from the initializer
and added

require 'ember_cli'

to lib/my_engine.rb

and that exception is gone now, but when I go to the mounted route once my parent application started, I've got a new exception Routing Error uninitialized constant MyEngine::EmberCli

I wonder should we have an Ember CLI configuration setting similar to Device when it is mounted in engine?

https://github.com/plataformatec/devise/wiki/how-to:-use-devise-inside-a-mountable-engine#configuration

Devise.setup do |config|
  config.router_name = :my_engine
end

@paxer
Copy link
Author

paxer commented Feb 8, 2018

the reason why I've got 'Routing Error uninitialized constant MyEngine::EmberCli' was because of

  class Engine < ::Rails::Engine
    isolate_namespace MyEngine

if I comment isolate_namespace MyEngine and then add a few changes in initializer

EmberCli.configure do |c|
  c.app :frontend, path: 'engines/my_engine/frontend'
end

and finally in frontend/config/environment.js

 rootURL: '/the_route_i_mount_my_engine_in_parent_app',

it works!

However I need to make it work with isolate_namespace MyEngine... so still an open issue

@paxer
Copy link
Author

paxer commented Feb 8, 2018

finally managed to make it work with isolate_namespace MyEngine

I've set in routing custom controller

  mount_ember_app :frontend, to: '/', controller: :frontend

and added this controller to my engine

module MyEngine
  class FrontendController < EmberCli::EmberController
  end
end

and it works!

I am not sure is this the right way to do it? Happy to send a PR to updated Readme if this is the correct way how to add ember-cli-rails to a mountable rails engine.

P.S. I have not had a chance to deploy it, in my case it is Heroku, so it may not actually work in production... will see

@seanpdoyle
Copy link
Contributor

@paxer thanks for working out all of those details!

My gut reaction to your comments in #558 (comment) is that you're taking the proper approach by namespacing your Ember controller in the module that corresponds to your engine, though my experience with Rails engines is pretty limited.

Happy to send a PR to updated Readme if this is the correct way how to add ember-cli-rails to a mountable rails engine.

That would be great! I'd love to look over that PR if you're willing to submit one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants