Routing Issue in Rails 4

50 views Asked by At

I have created a form useing form_for -

 = form_for @category, url: url_for(:controller => 'admin/category',:action => new_record ? "create" : "update"), name: 'udfFieldForm', id: 'udfFieldForm',:method =>'POST', remote: true do |f|

controller is look like-

 class Admin::CategoryController < ApplicationController
   def create
   end
   def update
   end
 end

route defined as -

namespace :admin do
   get 'category/:action' => 'category#index', :as => :category
   resource :categories
end

When i have submit form it through an error like -

AbstractController::ActionNotFound (The action 'category' could not be found for AdminController):

Here category is a controller under admin directory but it's looking for category action in admin controller. here i want to call category controler.

Please help me , where is the issue?

2

There are 2 answers

0
Arvind Rajput On BEST ANSWER

Need To Update Routes Like as with in admin namesapce

post 'category/:action'=> 'category', action: :create
patch 'category/:action'=> 'category', action: :update
2
Ely On

The application expects a controller named AdminController with a method named category, but it cannot find it. That is what the error message says and this how you created the link ...url: url_for(:controller => 'admin/category'...

I think that is wrong, since obviously you don't have a category method/action in your AdminController.