Defining Singleton Resource

0 views
Skip to first unread message

David

unread,
Mar 16, 2009, 6:17:05 AM3/16/09
to resource_controller
If I do the following ...

class MyController < ResourceController::Singleton
actions :new, :create, :destroy

{ other stuff }
end

... and activate the destroy action, I get an error

undefined method `index' for class `MyController'
/opt/local/lib/ruby/gems/1.8/gems/resource_controller-0.5.3/lib/
resource_controller/class_methods.rb:20:in `undef_method'
/opt/local/lib/ruby/gems/1.8/gems/resource_controller-0.5.3/lib/
resource_controller/class_methods.rb:20:in `actions'
/opt/local/lib/ruby/gems/1.8/gems/resource_controller-0.5.3/lib/
resource_controller/class_methods.rb:20:in `each'
/opt/local/lib/ruby/gems/1.8/gems/resource_controller-0.5.3/lib/
resource_controller/class_methods.rb:20:in `actions'

If I subsequently change the controller to have

actions :index, :new, :create, :destroy

Everything works fine.

grin

unread,
Apr 30, 2009, 4:00:41 PM4/30/09
to resource_controller
Hi David,

By default the destroy action redirects to collection_url, but for
singletons the index action is undefined so that's why you get the
error. Try to redefine the action like this:

destroy.wants.html {redirect_to my_url}

which will redirect to my_url instead of collection_url (index
action).
Reply all
Reply to author
Forward
0 new messages