# A Rails 3 centric Gem with it's own routes.rb?

**URL:** <https://www.ruby-forum.com/t/a-rails-3-centric-gem-with-its-own-routes-rb/192343>\
**Category:** Rails\
**Created:** [July 28, 2010, 6:34pm UTC](https://www.ruby-forum.com/t/a-rails-3-centric-gem-with-its-own-routes-rb/192343 "2010-07-28T18:34:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [July 28, 2010, 6:34pm UTC](https://www.ruby-forum.com/t/a-rails-3-centric-gem-with-its-own-routes-rb/192343/1 "2010-07-28T18:34:48Z")

</div>

I am working on a Gem for Rails 3 apps. In it, I want to include  
another GEM/lib/app/config/routes.rb to have gem level access to add  
new routes non programmatically. i.e., not runtime generated.

During Gem initialization I am adding the gem’s lib/app/config dir to  
$LOAD\_PATH and AS’s Dependencies module like so.

path = File.join(Rails.root, ‘/vendor’, ‘sitecontrol’, ‘lib’,  
‘sitecontrol’, ‘app’, ‘config’)  
$LOAD\_PATH \<\< path  
ActiveSupport::Dependencies.load\_paths \<\< path  
ActiveSupport::Dependencies.load\_once\_paths.delete(path)

Outputting $LOAD\_PATH is showing that the gem’s lib/app/config dir has  
been added.

GEM/lib/app/config/routes.rb looks like this.

SitecontrolIntegrationEnv::Application.routes.draw do |map|  
match ‘login’, :to =\> ‘user\_sessions#new’  
end

When running my specs I get “undefined local variable or method  
`login\_path’”. If I add the same route to Rails’ standard RAILS/app/  
config/routes.rb the spec will pass.

How can I go about adding routes in this way from my gem lib?

Thanks so much.  
Elliott G

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [July 29, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/a-rails-3-centric-gem-with-its-own-routes-rb/192343/2 "2010-07-29T21:21:11Z")

</div>

Any thoughts on this one guys?

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [July 30, 2010, 5:51pm UTC](https://www.ruby-forum.com/t/a-rails-3-centric-gem-with-its-own-routes-rb/192343/3 "2010-07-30T17:51:42Z")

</div>

I solved the problem.

I was assuming that since I was duplicating the standard Rails dir  
structure in my gem that Rails would load files automatically if their  
parent dir was on $LOAD\_PATH. I was wrong. From now on, I will only  
assume that Rails is loading only one file automatically (rails/  
init.rb).

My gem is called Sitecontrol… I just added a require ‘sitecontrol/  
config/routes’ from my gem’s initial lib file (sitecontrol.rb) to the  
extra routes.rb file I added.
