English 中文(简体)
铁路3个发动机级从母体看
原标题:Reopening Rails 3 engine classes from parent app

现在,你可以在发动机<代码>/app目录内重开发动机类别,简单地在括号中添加相同的类别<代码>/app。 例如:

/my_engine/app/controllers/users_controller.rb
/my_app/app/controllers/users_controller.rb

即使在母体有相同名称的档案的情况下,从my_engine<>/code>上存档。 详情如下:

http://www.cowboycoded.com/2011/02/28/why-you-cant-reopen-rails-3-engine-classes-from-the-parent-app/

我正在寻找一种工作,使我能够把同一档案名称/格按与父母相同的道路,重新开张,而不是压倒这个类别。 Maybe 我失踪是显而易见的。 我能够用一个单独的档案(不同的档案名称)来进行这项工作,该档案使用“等值”,但我对这种办法并不感到非常高兴。 任何关于为此寻找解决办法的想法?

I am also wondering if there is a reason behind this restriction, or is it just a result of how rails loads files (see included link) and not intentional. It seems to me that changing the load behavior of engines to allow reopening classes in this manner would be a good feature in rails. I know it confused me at first, and I am sure other developers will struggle with this problem as well.

最佳回答

铁路 3.2.2 鲁比拉1.9 转而重载稀料,然后使用<代码>require_dependency <>/code”要求发动机的舱面,然后重新开放舱面并增加功能。 即便是在发展环境中(即班重载)。

# development.rb
config.reload_plugins = true 

# app/controllers/my_engine/documents_controller.rb
require_dependency MyEngine::Engine.root.join( app ,  controllers ,  my_engine ,  documents_controller ).to_s

module MyEngine
  class DocumentsController
    def show
      render :text =>  different 
    end
  end
end
问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...