Let's say I have created a mountable engine into ~/my_engine folder:
rails plugin new my_engine --mountable
How do I mount this engine into a Rails 3.1 app, that is at the same directory level (e.g. ~/my_app)?
There is a good writeup of the process here:
http://www.builtfromsource.com/2010/12/13/mountable-engines-in-rails-3-1-beta-getting-started/
In short, add this to your main app's Gemfile:
gem 'my_engine', :path => '../my_engine'
And run bundle install/bundle update. Add this to your main app
mount MyEngine::Engine => '/my-engine-url'
Related
I've been following the guide around rails engines here: http://guides.rubyonrails.org/engines.html and have created the example engine blorgh and also have a barebones rails app.
I generated my engine following this command:
rails plugin new blorgh --mountable
And I can confirm that I have: /lib/blorgh.rb in my engine. Now going by the guides it states you simply need to add the following to your main app:
gem 'blorgh', path: 'engines/blorgh'. Now in my main rails app when I try to do bundle install I get:
The path /Users/home/projects/unicorn/engines/blorgh does not exist.
I'm pretty sure I'm missing something basic here.
The path /Users/home/projects/unicorn/engines/blorgh does not exist
Because Rails application going to Search ‘engines’ folder that's stores the engines (even if you just have one!) in your case /engines/blorgh not found any engine.
The path option in Gemfile is for using gem that is on the path specified.
And it have to be the directory where the unpacked gem is located.
In your case it looked to engines/blorgh relative to your working directory. Which is on /Users/home/projects/unicorn/engines/blorgh.
And /Users/home/projects/unicorn/engines/blorgh is simply doesn't exists.
To fix it, make sure you put the engine on /Users/home/projects/unicorn/engines/blorgh
Hello I am new to Rails Engine , I have followed ruby official documentation for "Creating Rails Engine" http://guides.rubyonrails.org/engines.html After creating Plugin I have added plugin name in gemfile to load the engine
gem 'product_search', :path => 'product_search/engines/product_search'
but it always through error The path /var/www/sites/web_service/product_search/engines/product_search does not exist.
The Plugin name is "ProductSearch"
I have also changes the pathname
gem 'product_search', :path => 'ProductSearch/engines/product_search'
[It is the Directory structure of the plugin:]
http://i.stack.imgur.com/hRh1X.png
Thanks in advance..!!!
From the documentation:
At the root of this brand new engine's directory lives a
blorgh.gemspec file. When you include the engine into an application
later on, you will do so with this line in the Rails application's
Gemfile:
gem 'blorgh', path: "vendor/engines/blorgh"
Don't forget to run bundle install as usual. By specifying it as a gem
within the Gemfile, Bundler will load it as such, parsing this
blorgh.gemspec file and requiring a file within the lib directory
called lib/blorgh.rb. This file requires the blorgh/engine.rb file
(located at lib/blorgh/engine.rb) and defines a base module called
Blorgh.
I'm building a mountable engine that is dependent on another 'core' (unmounted) engine that I have written.
In my container app's Gemfile I add the core engine and the optional engine's git repo's.
In my mountable engine, where should I add its dependencies on the 'core' engine to be used in the dummy app for testing? (rspec)
I tried adding this in the mountable engine's gemspec:
require "my_core"
...
s.add_dependency "my_core", :git => "https//github.com/me/my_core.git"
I am doing this by declaring the dependency in the engine Gemfile
if ENV['LOAD_GEMS_FROM_LOCAL'] == '1'
gem 'my_core', path: File.expand_path("../../my_core", __FILE__)
else
gem 'my_core', git: 'https//github.com/me/my_core.git'
end
The LOAD_GEMS_FROM_LOCAL lets me load the other engine from the filesystem, so I can develop both engines at the same time.
We are using rails engine in our 3.2.8 app. When we want to include an engine in our rails app/another engine, we did include the engine in gemfile(gemspec) and mounting it in routes.rb. However we notice that if we remove the mounting command in routes.rb and only leave gem engine in gemfile (gemspec) file unchanged, the same rpsec cases can pass without error. This leads us wondering what's the difference between mounting rails engine in routes.rb and put it in gemfile (gemspec for engine) or do both. Any help is appreciated.
When you want to mount a Rails Engine in a Rails application, you add the gem to the application's Gemfile (so that the gem's source code will be required when the application boots). You specify the mount path in the application's config/routes.rb so that the Engine's controllers will respond to HTTP requests:
Rails.application.routes.draw do
mount MyGem::Engine => "/mygem"
root to: 'home#index'
end
When you are creating an engine, by default, the generator will create a "dummy" application that your tests will use to test your engine. My guess is that your tests are still passing because you still have this mount path specified in the dummy app.
I've created a simple mountable application in rails 3.1.3 using command:
$ rails plugin new appToMount --mountable
Than I added some MVC to it. And now I want to mount it to another normal Rails application. The problem is I have no idea how to do this. I tried asking google, but I failed. There are plenty of examples how to create mountable app, but none explaining how to mount it.
You have to add it to the config/routes.rb of your rails app. Something like the following:
mount AppToMount::Engine, :at => '/'
And I recommend you to package your engine as a gem. You can use bundler to create the new gem with the command
bundle new app_to_mount
And finally, you should add the Gem to your gemfile, using the path option. Like in the following:
gem 'app_to_mount', path: '/your/home/app_to_mount'