views:

31

answers:

2

Hi folks,

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

+1  A: 

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

marcgg
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. ;-)
unclaimedbaggage
+1  A: 

@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/

Keith Schacht
Perfect - many thanks. ;-)
unclaimedbaggage