4

I'm trying to write my first rails 3 gem - everything works well, except for routes - I can't seem to get them working. It's possible this is a very simple error - as mentioned, it's my first experience with engines. The gem itself is very, very basic - literally just one scaffold

My gem's config/routes file:

class ActionController::Routing::RouteSet
  resources :frogs
end

...And when I try to start the server, I get the following error:

/home/john/.rvm/gems/ruby-1.9.2-p0/gems/cancandevise-0.1.0/config/routes.rb:3:in <class:RouteSet>': undefined method resources' for ActionDispatch::Routing::RouteSet:Class (NoMethodError)

Any suggestions much appreciated. At the present moment, the gem is nothing more than a very basic rails-generated 'frog' scaffold

Cheers, - JB

2
  • Is this a typo resources: frogs; as it should be resources :frogs? Might be the cause of your problem... Oct 8, 2010 at 13:18
  • Thankfully it was correct in the file. Cheers anyway...that woulda been embarrassing. ;-)
    – PlankTon
    Oct 8, 2010 at 13:27

3 Answers 3

5

@marcgg, I believe that's the syntax for a regular rails app, but I think he's talking about an engine.

@unclaimedbaggage, your engine/gem routes file should look like this:

Rails.application.routes.draw do |map|
  resources :frogs
end

I made an example engine that touches on all the common setup issues I encountered when creating my first gem, you might find it helpful to reference:

http://keithschacht.com/creating-a-rails-3-engine-plugin-gem/

0
2

I'm not sure if I get why you're using a routeset. What file did you show? Did you try this:

   YourApp::Application.routes.draw do |map|  
     resources :frogs
   end

More info here: http://asciicasts.com/episodes/203-routing-in-rails-3

1
  • I couldn't do this because, being part of a gem, 'YourApp' could have any value. However you're kinda right - I shoulda been drawing. I got it working with Rails.application.routes.draw do |map| ...Thanks. ;-)
    – PlankTon
    Oct 8, 2010 at 17:00
0

Just wanted to add an alternative here, as I'm not sure @Keith Schact is doing it the conventional way, this worked for me:

MyEngine::Engine.routes.draw do
  resources :frogs
end

then in the application that requires the gem:

mount MyEngine::Engine => '/my_engine', :as => :some_namespace

The url you will get is then:

http://myserver.com/some_namespace/frogs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.