views:

51

answers:

1

So I am creating a website that I want to have an admin directory in rails 1.8.x and I'm struggling a bit to get the form_for to link to the right controller. I am trying to be RESTful. What I basically want is an admin page that has a summary of actions which can then administer sub models such as:

/admin (a summary of events)
/admin/sales (edit sales on the site)
/admin/sales/0 (the normal RESTful stuff)

I can't use namespaces since they were introduced in Rails 2.0 (production site that I don't want to mess with updating rails and all that).

Anyway, what I have in the routes.rb is:

map.resource :admin do |admin|
  admin.resources :sales
end

I am using the map.resource as a singleton as recommended by another site.

The problem comes in when I try to use the form_for to link to the subresource RESTfully. If i do :

form_for(:sales, @sale)

it never links to the right controller no matter what I try. I have also tried:

form_for [@admin, @sale] do |f|

and that does not work either (I am guessing since admin is a singleton which does not have a model, it's just a placeholder for the admin controller). Am I supposed to add a prefix or something? Or something into the sales controller to specify that it is a subcontroller to admin? Is there an easier way to do this without manually creating a bunch of routes? Thanks for any help.

A: 

You can use controller, action and html options something like following.

<%= form_for :sales, :controller=>controllerName, :action=>actionName, :id=>idParameter}, :html=>{:onsubmit=>"someFunction()"} do |f| %>


            |
            |
            |




<% end %>
Salil