Differences between railties and engines in Ruby On Rails 3

Railtie can probably do what you describe, but it may be more desirable to use an engine. The engine can have its own configuration and also acts like a Rails application, since it allows you to include the /app directory with controllers, views and models in the same manner as a regular Rails app. Read … Read more

Render engine within application layout

I have successfully used layouts of my parent application in my engines. Firstly, based on Section 4.3.2 of the Rails Guides (Engines), in order to access the parent applications ApplicationController’s variables (like session, as you’re using above), you need to replace the engine’s application_controller.rb from this that you currently have: module Module1 class ApplicationController < … Read more

How to add dependency of a local gem to a rails plugin/engine, in .gemspec file

While developing 2 gems, gem1 and gem2, requiring that gem1 locally depends on gem2 is quite handy. You can’t do this in your gemspec, however, you can do so in your gem’s Gemfile! # Gemfile source “https://rubygems.org” gem ‘gem2’, :path => ‘../gem2’ # Specify your gem’s dependencies in gem1.gemspec gemspec And then in your gemspec, … Read more

Testing Rails 3.1 mountable engine with Rspec

I am using RSpec with a Rails engine without issues. I created my plugin using the following switches: -T –full –dummy-path=spec/dummy. -T excludes test/unit –full indicates that the plugin is an engine –dummy-path is simply so that we don’t get a test directory (the default is test/dummy). From there I used the spec_helper from the … Read more

Named routes in mounted rails engine

The right way I believe the best solution is to call new_post_path on the Engine’s routes proxy, which is available as a helper method. In your case, the helper method will default to basic_app_engine, so you can call basic_app_engine.new_post_path in your views or helpers. If you want, you can set the name in one of … Read more

Rails Engine – Gems dependencies, how to load them into the application?

Include them in your gemfile and run bundle install. Then require them in your lib/<your_engine>/engine.rb file. Don’t forget to require rubygems require ‘rubygems’ require ‘paperclip’ require ‘jquery-rails’ require ‘rails3-jquery-autocomplete’ require ‘remotipart’ require ‘cancan’ Then in your host app (The app where you included your gem) run bundle install/ bundle update (bundle update did the trick … Read more

Ruby on Rails 3 – Reload lib directory for each request

I couldn’t get any of the above to work for me so I dug in the Rails code a bit and came up with this: New file: config/initializers/reload_lib.rb if Rails.env == “development” lib_reloader = ActiveSupport::FileUpdateChecker.new(Dir[“lib/**/*”]) do Rails.application.reload_routes! # or do something better here end # For Rails 5.1+ ActiveSupport::Reloader.to_prepare do lib_reloader.execute_if_updated end # For Rails … Read more

Rails 3.1: Engine vs. Mountable App

I have noticed the following: Full Engine With a full engine, the parent application inherits the routes from the engine. It is not necessary to specify anything in parent_app/config/routes.rb. Specifying the gem in Gemfile is enough for the parent app to inherit the models, routes etc. The engine routes are specified as: # my_engine/config/routes.rb Rails.application.routes.draw … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)