ashwinm ashwinm - 1 year ago 151
Ruby Question

Undefined method with “_path” while using simple_form_for

I am having problem with routing when using simple_form_for. I understand it is something to do with pluralizing but the same form is working perfectly for edit/update method.

undefined method `companies_path'
Did you mean? companys_path


def new
@company =

def create
@company =

redirect_to @company
render 'new'



= simple_form_for @company do |f|
= f.input :name
= f.input :description
= f.input :website

= f.button :submit

rake routes

companys GET /companys(.:format) companys#index
POST /companys(.:format) companys#create
new_company GET /companys/new(.:format) companys#new
edit_company GET /companys/:id/edit(.:format) companys#edit
company GET /companys/:id(.:format) companys#show
PATCH /companys/:id(.:format) companys#update
PUT /companys/:id(.:format) companys#update
DELETE /companys/:id(.:format) companys#destroy

I guess the problem is, Edit/update is going for 'companys_path' and new/create is going for 'companies_path'. Any help is appreciated.

Answer Source

Controller name should be plural so in your case it should be companies_controller

Follow these steps to change it

  • Rename controller to companies_controller.rb
  • Change controller class name to

    class CompaniesController < ActionController::Base
      # controller code
  • Change in routes.rb

    resources :companies
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download