如何修改 Rails 引擎以需要我的库?

发布于 2024-10-31 03:05:06 字数 698 浏览 1 评论 0原文

我有一个 Rails 引擎(别人的 gem),我试图通过添加另一个 gem 作为依赖项来修改它。我似乎不知道如何让引擎需要该库。我尝试了各种不同的方法,但似乎无法让它发挥作用。

我的主应用程序 Gemfile 我有引擎:

gem 'enginegem'

在引擎的 gemspec 中我有:

s.add_dependency 'somethinggem', '~> 1.0'

在引擎中,有一个我试图通过添加此 acts_as_something 方法来修改的模型:

class Page < ActiveRecord::Base
  acts_as_something
end

并且有一个我的控制器我正在尝试修改:

class PagesController < ApplicationController
  around_filter :do_something

  def do_something
    my_var = 'foobar'
    Something.do_something_with my_var do
      yield
    end
  end
end

将此库添加为引擎的依赖项并让它需要该库的适当方法是什么?

I have a Rails engine (someone else's gem) that I am trying to modify by adding another gem as a dependency. I can't seem to figure out how to get the engine to require the library. I've tried all sorts of different things, but I can't seem to get it to work.

My main app Gemfile I have the engine:

gem 'enginegem'

In the engine's gemspec I have:

s.add_dependency 'somethinggem', '~> 1.0'

In the Engine, there is a model that I am trying to modify by adding this acts_as_something method:

class Page < ActiveRecord::Base
  acts_as_something
end

And there is a controller that I am trying to modify:

class PagesController < ApplicationController
  around_filter :do_something

  def do_something
    my_var = 'foobar'
    Something.do_something_with my_var do
      yield
    end
  end
end

What is the appropriate way to add this library as a dependency to the engine and have it require the library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅 2024-11-07 03:05:06

如果您告诉我们您要修改哪个宝石,将会有所帮助。

在大多数宝石中,您都会有一个 lib/enginegem.rb,可能是需要宝石的最佳位置:

require 'somethinggem'

编辑:虽然这个答案对OP没有帮助(请参阅下面的评论),但我将其保留在这里,因为它可能对其他人有帮助。

编辑 2:每个尝试创建引擎的人都应该看看 devise 的代码。如果您想要更具指导性的方法,请尝试 Jose Valim 的Crafting Rails Applications一书。事实上,如果您认真对待这个引擎,您应该两者都做。

It'd help if you told us which gem you're trying to modify.

In most gems you will have a lib/enginegem.rb, there is probably the best place to require the gem:

require 'somethinggem'

EDIT: Although this answer didn't help the OP (see comments below), I'll keep it here, because it may help others.

EDIT 2: Everybody who is trying to create an engine should take a look at devise's code. If you want a more didactic approach, try Crafting Rails Applications book from Jose Valim. In fact, if you're serious with this engine, you should do both.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文