How to enable a controller with a Ruby on Rails stone?

I am trying to contribute to an open source project, and I need a controller to handle several forms that need to be submitted.

I created these controllers inside a directory inside the gem named app/controllers/gemname/my_controller.rb .

However, when I try to access the controller, it does not seem to load (I get a name error as if I typed something like NonExistentController).

How to load my controller using a gem?

Thanks!

+8
ruby ruby-on-rails rubygems gem ruby-on-rails-plugins
source share
2 answers

Suppose your gem is called MyGem , and you have a controller called SuperController that you want to use in the application. Your controller should be defined as:

 module MyGem class SuperController < ApplicationController def whatever ... end end end 

and in your gem directory it should be in app/controllers/my_gem/super_controller.rb (not in the lib folder). Check out the source for Devise as they do the same.

[Edit] You can learn something from the Guide to Starting Your Own Homemade Rails Engine Regarding Your Current Project.

+10
source share

The guidance in Brandon's answer is very useful, but applies only to rails 3.0. Starting with version 3.1 you can create a plugin. For example: rails plugin new my_engine --mountable

See this helpful guide:
http://namick.tumblr.com/post/17663752365/how-to-create-a-gemified-plugin-with-rails-3-2-rspec
(> Rails 3.0)

Official Rails Guide (Edge):
http://edgeguides.rubyonrails.org/engines.html
http://edgeguides.rubyonrails.org/plugins.html

Old enginex:
https://github.com/josevalim/enginex
(3.0 only)

0
source share

All Articles