Rails Routes Namespaces and form_for

If you have namespaced routes the best way is:

class Admin::BusinessesController < ApplicationController
  def new
    @business = Business.new
  end
end

in routes.rb:

namespace :admin do
  resources :businesses
end

In view:

form_for [:admin, @business] do |f|...

The Docs: http://guides.rubyonrails.org/form_helpers.html section 2.3.1 Dealing with Namespaces

Regarding your case:

In routes.rb everything is o’k. In the view you should write url explicitly because you have variable in controller other than controller name:

form_for @business, :url => business_registration_path do |f|...

I suppose that in businesses/registration_controller you have something like this:

class Businesses::RegistrationController < ApplicationController
  def new
    @business = Business.new
  end
end

And one remark: I wouldn’t create registration_controller for registering a new business. I think that keeping business related actions in business_controller is much clearer.

Leave a Comment