Q:

How to use two controllers with one model in Rails

I have an Order model. Customers interact with the Order model through an Orders controller. Admins interact with the Order model through a Purchases controller.
Mostly it's working, except this happens:

An admin user goes to new_purchase_path
The app uses the "create" action in the purchases controller, as
    expected
The app then uses the "new" action in the order controller (not the
purchases controller)
App then renders the "app/purchases/new" view (not the
"app/orders/new" view), despite the fact that it has switched to using the orders controller
After the admin creates the order, the app then renders the
"app/orders/show" view using the orders controller

What I really need to happen is this:

An admin users goes to new_purchase_path
The app then uses the "create" action in the purchases controller
The app then uses the "new" action in the purchases controller
The app then renders the "app/purchases/new" view
After the admin creates the order, the app then renders the
"app/purchases/show" view using the purchases controller

In app/controllers/purchases_controller.rb I have this:
  def new
    @purchase = Order.new
    respond_with @purchase
  end

If have tried variations like...
  def new
    @purchase = Order.new
    respond_with @purchase, :controller => :purchases
  end

...but nothing like that is documented for respond_with, and naturally it doesn't work. What can I do?

A:

A few observations:

You should not use *respond_with* in the new action as it doesn't make sense for anything but HTML.
You should use namespaces if you want to make some controllers for admins only. See http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing. That way you also don't need to change the name.

A:

The answer to this question is related to your last question. I've updated my answer there, but in a nutshell, the problem is not with respond_with (which as @jiri-pospisil points out you don't really need) but with your form generated by simple_form_for. The action url in that form defaults to /orders because @purchase is an instance of the class Order.
To fix that problem, specify the url in the form:
= simple_form_for @purchase, :as => :purchase, :url => purchases_path(@purchase) do |f|
  = f.error_notification
  = f.input :name
  = f.button :submit

You'll then find that you have another problem: after the new order (purchase) is created, respond_with will redirect to the show action of OrdersController. To fix that, you can use the location option:
def create
  @purchase = Order.new(params[:purchase])
  if @purchase.save
    respond_with(@purchase, :location => purchases_path(@purchase))
    ...

As you can probably tell at this point, using two controllers for a single model this way becomes somewhat convoluted, so you might want to consider namespaces instead.

