简体   繁体   中英

How to modify a gem files in rails 3 project

我正在使用带有捆绑器的Rails 3,我使用捆绑器安装了gem,现在我需要通过修改gem的控制器来稍微修改gem的流程,我应该怎么做,我确定有一个命令在本地安装文件,以便我可以对其进行修改,我试图通过创建另一个具有相同名称的控制器来覆盖控制器,但听起来不起作用。

将其分叉在github上,进行更改,然后将您的gemfile指向分叉的仓库,如下所示:

gem "contact-us", :git => "git://github.com/eqbal/contact-us.git"

You should just be able to make a controller, inherit from the gem controller and override the method behavior as you see fit

class MyController < ContactUs::ContactsController
  def create
    # my code that changes the behavior
  end
end

And then you may have to tell your routes to go to your controller

resources :contacts,
  :controller => 'my_controller'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM