views:

83

answers:

2

I'm getting the following error:

Unknown action

No action responded to show. Actions: activate, destroy, index, org_deals, search, and suspend

Controller:

class Admin::HomepagesController < Admin::ApplicationController

def org_deals
@organization = Organization.find(:all)
end

Routes:

   map.root :controller => 'main'
   map.admin '/admin', :controller => 'admin/main'

   map.namespace :admin do |admin|
   admin.resources :organizations, :collection => {:search => :get}, :member => {:suspend => :get, :activate => :get}

To note: This is a controller inside of a controller.

Any idea why this is defaulting to show?

Update:

I updated what the routes syntax is. Read that article, and tried quite a few variations but its still adamantly looking for a show.

+1  A: 

Firstly, it looks like your routes file has the wrong syntax. If you are trying to establish routes for nested resources, you'd do it like so:

map.resources :admin
  admin.resources :organizations
end

This would give you paths such as:

/admin/
/admin/1
/admin/1/organizations
/admin/1/organizations/1

The mapping from route to controller/action is done via a Rails convention, where HTTP verbs are assigned in ways that are useful for the typical CRUD operations. For example:

/admin/1/organizations/1

would map to several actions in the OrganizationsController, distinguished by the type of verb:

/admin/1/organizations/1 # GET -> :action => :show
/admin/1/organizations/1 # PUT -> :action => :update
/admin/1/organizations/1 # DELETE -> :action => :destroy

"Show" is one of the seven standard resourceful actions that Rails gives you by default. You can exclude "show" with the directive :except => :show, or specify only the resourceful actions you want with :only => :update, for example.

I recommend you look at Rails Routing from the Outside In, which is a great introduction to this topic.

EDIT

I see I ignored the namespacing in my answer, sorry. How about this:

  map.namespace(:admin) do |admin|
    admin.resources :homepages, :member => { :org_deals => :get }
  end

This will generate your org_deals action as a GET with an id parameter (for the organization). You also get a show route, along with the six other resourceful routes. rake routes shows this:

org_deals_admin_homepage GET /admin/homepages/:id/org_deals(.:format) {:controller=>"admin/homepages", :action=>"org_deals"}

Of course your homepages_controller.rb has to live in app/controllers/admin/

EDIT redux

Actually, you want organizations in the path, I'll bet, in which case:

  map.namespace(:admin) do |admin|
    admin.resources :organizations, :controller => :homepages, :member => { :org_deals => :get }
  end

which gives you:

org_deals_admin_organization GET    /admin/organizations/:id/org_deals(.:format) {:controller=>"admin/homepages", :action=>"org_deals"}
zetetic
I had posted the wrong syntax. I updated it above. I'm think that that somehow member and collection is overriding the normal action going on. Not sure..
Trip
See my edits. Does that help?
zetetic
Yes, you have an amazing response. Absolutely. My objective is probably not so RESTful as I'm just trying to create a side view that has nothing to do with CRUD. In this case, I tried making a 'named route' within a loop. admin.namespace :organizations do |organization| <break> organization.org_deals 'org_deals', :controller => 'organizations', :action => 'org_deals' <break> end . But this still defaults to a show. I assume I need to add member in there. I tried your's adding org_deals to member but it's looking for an Org /:id/ which it doesn't need because its irrelevant to them specificall
Trip
If you don't want the :id, don't use resources -- just create a named route, or use `map.connect`
zetetic
admin.namespace :organizations do |organization| organization.org_deals 'org_deals', :action => 'org_deals' endThis creates in rake routes, the proper link, but it's still looking for the show action when it loads the path. I also tried the connect way too. Routes were right, but it still looked for show.
Trip
A: 

By specifying admin.resources ... you are telling Rails you want the seven default different routes in your application. If you do not want them, and only want the ones you specify, do not use .resources. Show is called because that's the default route called for a GET request with a path such as /admin/id when you have the default resources.

JRL
so could i write something like this then 'admin.org_deals 'org_deals', :controller => 'admin/organizations/', :action => 'org_deals' . And if so, would the path be, 'org_deals_admin_organization_path ?
Trip