rails-engines

Listing 'rake routes' for a mountable Rails 3.1 engine

百般思念 提交于 2019-11-27 14:34:44
问题 I'm working on a mountable engine for use with Rails 3.1, and I want to list the engine's routes. I created the engine using: $ rails plugin new rails_blog_engine --mountable And edited the 'test/dummy/config/routes' file to read: Rails.application.routes.draw do mount RailsBlogEngine::Engine => "/blog" end ...and 'config/routes' to read: RailsBlogEngine::Engine.routes.draw do resources :posts end I want to list the routes generated for ':posts', but it's not clear how I can do this. When I

Migrations in Rails Engine?

依然范特西╮ 提交于 2019-11-27 09:33:11
问题 I have multiple rails applications talking to the same backend and I'd like them to share some migrations. I setup a rails engine (with enginex), I can share anything (controllers, views, models,...) but no migrations. I can't make it work ! I tried to create a file db/migrate/my_migration.rb but in my main application if I do : rake db:migrate It doesn't load them. After some googling it appears there was some recent work on this and it seems this has been merge to rails master. I'm with

Rails engines extending functionality

牧云@^-^@ 提交于 2019-11-27 07:29:01
I have an engine which defines some models and controllers. I want to be able to extend functionality of some models/controllers in my application (eg. adding methods) without loosing the original model/controller functionality from engine. Everywhere I read that you simply need to define controller with the same name in your application and Rails will automatically merge them, however it doesn't work for me and controller in engine is simply ignored (I don't think it's even loaded). Peder require MyEngine::Engine.root.join('app', 'models', 'my_engine', 'my_model') before the model class

Testing Rails 3.1 mountable engine with Rspec

試著忘記壹切 提交于 2019-11-27 05:06:07
问题 I started making a Rails 3.1 engine, and I'm having a hard time testing it using rspec. First of all, if I run rails g integration_test whatever it creates a regular integration test in tests/integration instead of spec/requests (the rspec-rails gem is installed and required as a development dependency in the gemspec file) Also, when I run a spec test I get an error saying the table corresponding to the model I'm testing has not been created. I tried rake engine_name:install:migrations and

Rails 3.1: Better way to expose an engine's helper within the client app

自闭症网瘾萝莉.ら 提交于 2019-11-27 04:22:05
问题 I have found a few articles addressing the issue of helpers within an engine not being accessible to the consuming (parent) application. To make sure we are all on the same page, let's say we have this: module MyEngine module ImportantHelper def some_important_helper ...do something important... end end end If you look at the rails engine documentation in the "Isolated engine's helpers" (L293), it says: # Sometimes you may want to isolate engine, but use helpers that are defined for it. # If

Extending controllers of a Rails 3 Engine in the main app

白昼怎懂夜的黑 提交于 2019-11-27 03:40:34
I am using a Rails engine as a gem in my app. The engine has PostsController with a number of methods and I would like to extend the controller logic in my main app, e.g. to add some methods. If I just create PostsController in the main app, then the engine's controller is not loaded. There is a solution proposed in question Rails engines extending functionality based on altering ActiveSupport::Dependencies#require_or_load Is it the only/correct way to do this? If yes, where do I put that piece of code? EDIT1: This is the code suggested by Andrius for Rails 2.x module ActiveSupport:

A way to add before_filter from engine to application

亡梦爱人 提交于 2019-11-27 03:36:59
问题 Without a lot of specific code, this is just vague, but I'll provide what I can. Given a rails engine, a basic engine and not a mountable engine in its own space, how do I make methods from the engine available to the application as a before_filter for the applications controllers? I've been looking through the Devise code, because what I want to is similar from my experience with Devise, but I'll admit I don't understand a lot of what I'm going over. I can do this if I put include Myengine:

Differences between railties and engines in Ruby On Rails 3

微笑、不失礼 提交于 2019-11-27 00:54:14
问题 I read a few documents on these arguments, but I did not understand clearly what they are, what are the differences between them and if one of them fits my needs. I need to write a piece of application which can be plugged in other application and I want to include it in other applications as a gem. Essentially I need a couple of models, one controller and no views, plus some initialization, support for configuration parameters coming from the hosting app and a generator. Am I on the right

Rails 3.1: Engine vs. Mountable App

淺唱寂寞╮ 提交于 2019-11-26 19:14:52
Can someone help me understand the differences between a Rails Engine and a Mountable app? In Rails 3.1, you can create either one with the "rails new plugin _ __ " command. rails plugin new forum --full # Engine rails plugin new forum --mountable # Mountable App When would you want to use one versus the other? I know you can package an Engine as a gem, for one. Is that not the case for Mountable Apps? What other differences are there? astjohn 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

Ruby on Rails 3 - Reload lib directory for each request

被刻印的时光 ゝ 提交于 2019-11-26 11:53:19
问题 I\'m creating a new engine for a rails 3 application. As you can guess, this engine is in the lib directory of my application. However, i have some problems developing it. Indeed, I need to restart my server each time I change something in the engine. Is there a way to avoid this ? Can I force rails to completely reload the lib directory or a specific file and his requirements for each request ? Thanks for your help :) 回答1: TL;DR put this in config/application.rb config.eager_load_paths += ["