ROR Form_with 一直给我一个 NoMethodError

ROR Form_with keeps giving me a NoMethodError

我确定这应该是一个简单的问题,但找不到解决方案(我是 ROR 的新手)。

这是我得到的错误:

-----错误-----

Agency::Clientmanagement#edit 中的 NoMethodError 显示 /home/ubuntu/environment/nacho/app/views/agency/clientmanagement/_form_client.html.erb 第 2 行出现的位置:

#ActionView::Base:0x007fcda8bd7ae0 的未定义方法“client_path” 你的意思? clients_path

<%= form_with 型号:@clientrecord do |f| %>

------这是我的路线------

root 'pages#home'
  get 'clients', to: 'clients#index'
  get 'agency', to: 'agency#index'
  get 'admin', to: 'admin#index'
  get 'clientview', to: 'agency#clientview'
  #post 'clientview', to: 'agency#clientview'
  
  namespace :admin do
    get "new", to: 'manager#new'
    get "add-user", to: 'manager#add-user'
    get "agencies", to: 'manager#agencies'
  end
  
  namespace :agency do
    resources :clientmanagement, only: [:show,:new, :create, :edit]
    resources :team, only: [:index, :show,:new, :create, :edit]
  end 

--------这是:admin/clientmanagementcontroller

class Agency::ClientmanagementController < ApplicationController
  before_action :require_agencyaccount
  before_action :user_clients
  before_action :set_client, only: [:show]
  # before_action :set_one_product, only: [:show]

  # def index
  #   @all_shoe_products = @all_products.where(main_category_id: MainCategory.find_by_name("shoes").id)
  # end

  def show
  end
  
  def new
  end
  
  def create
  end
  
  def edit
     @clientrecord = Client.find(params[:id])
  end

  private
  
  def user_clients
    @clients = User.find(current_user.id).clients
  end
  
  def set_client
    @client = Client.find(params[:id])
  end

--- 这是在 /agency/clientmanagement/{id}/edit

中呈现的部分形式的 form_with
<%= form_with model: @clientrecord do |f| %>

如有任何帮助,我们将不胜感激

在你的 routes.rb 文件中我没有看到 client_path 被定义。

选项1:您可以通过在客户端路径下添加以下路由来添加客户端路径:

Rails.application.routes.draw do
  get 'clients', to: 'clients#index'
  get 'client',  to: 'clients#show'
  ...
end

这将生成以下路径:

client_path   GET    /client(.:format)    clients#show

选项 2:如果您有 clients 的完整资源控制器,您可以添加

resources :clients

这将为 clients

生成所有 RESTful 条路线
     clients_path GET    /clients(.:format)          clients#index
                  POST   /clients(.:format)          clients#create
  new_client_path GET    /clients/new(.:format)      clients#new
 edit_client_path GET    /clients/:id/edit(.:format) clients#edit
      client_path GET    /clients/:id(.:format)      clients#show
                  PATCH  /clients/:id(.:format)      clients#update
                  PUT    /clients/:id(.:format)      clients#update
                  DELETE /clients/:id(.:format)      clients#destroy