Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails engine extends config/application.rb

I am in the process of writing a Rails engine but i am not sure how to extend my the config/application.rb

I guess i have to get to the application name somehow any ideas?

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module application_name
  class Application < Rails::Application
  end
end
like image 586
MZaragoza Avatar asked Nov 22 '13 00:11

MZaragoza


People also ask

What is application RB in Rails?

The configuration file config/application. rb and environment-specific configuration files (such as config/environments/production. rb ) allow you to specify the various settings that you want to pass down to all of the components. For example, you could add this setting to config/application.rb file: config.

What is the purpose of environment RB and application RB file?

In the environment. rb file you configure these run-levels. For example, you could use it to have some special settings for your development stage, which are usefull for debugging. The purpose of this file is to configure things for the whole application like encoding.

What are Rails configurations?

In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The configuration file config/application. rb and environment-specific configuration files (such as config/environments/production.

What is a Rails engine?

1 What are Engines? Engines can be considered miniature applications that provide functionality to their host applications. A Rails application is actually just a "supercharged" engine, with the Rails::Application class inheriting a lot of its behavior from Rails::Engine .


1 Answers

For a --full and --mountable engine

This will be generated for you.

module engine_name
  class Engine < ::Rails::Engine
  end
end

In you main applications gemfile add

gem 'engine_name', path: "/path/to/engine_name"

And in your applications config/routes.rb file

mount engine_name::Engine, at: "/<mount_point_you_choose>"

http://guides.rubyonrails.org/engines.html

Taken from the link above...

The --mountable option tells the generator that you want to create a "mountable" and namespace-isolated engine. This generator will provide the same skeleton structure as would the --full option, and will add:

Asset manifest files (application.js and application.css) A namespaced ApplicationController stub A namespaced ApplicationHelper stub A layout view template for the engine Namespace isolation to config/routes.rb:

like image 107
Aaron Mitchell Avatar answered Oct 20 '22 23:10

Aaron Mitchell