简体   繁体   English

无法自动加载常量控制器

[英]Unable to autoload constant Controller

I have a form that I am using for new and edit, and the functionality for index and clicking for a new form and edit works, but when I go to create or update the form returns a load error to another controller. 我有一个用于新建和编辑的表单,以及用于索引和单击以创建新表单并进行编辑的功能,但是当我创建或更新表单时,会向另一个控制器返回加载错误。

The controller is PathCreationsController in system and it wants to use the creations controller in another place and it wants to use it to define it..which is weird because I don't have anything set to do that. 该控制器是系统中的PathCreationsController,它想在另一个地方使用creations控制器,并且想用它来定义它。.这很奇怪,因为我没有任何设置要这样做。

I tried adding a url to the form and setting the method to put but when I do that to try and force the controller to work correctly it sets all the params to null in the database so I assumed thats not a valid way to fix this. 我尝试在表单中添加一个url并设置要放置的方法,但是当我尝试强制控制器正常运行时,它将数据库中的所有参数都设置为null,因此我认为这不是解决此问题的有效方法。

Here is the controller: 这是控制器:

class System::PathCreationsController < ApplicationController

  def index
    @paths = Path::Account.all
  end

  def new
    @paths = Path::Account.new
  end

  def edit
    @paths = Path::Account.friendly.find(params[:id])
  end

  def create
    @paths = Path::Account.new

    if @paths.save
      redirect_to system_path_creations_path(@paths)
    end
  end


  def update
    @path = Path::Account.find_by(slug: params[:id])
    if @path.update
      redirect_to system_path_creations_path(@path)
    end
  end
end

Here is the form: 形式如下:

    = form_for @paths do |f|
      %br
      .form-group
        = f.label :name, class: 'control-label'
        = f.text_field :name, class: 'form-control'
      .form-group
        = f.label :slug, class: 'control-label'
        = f.text_field :slug, maxlength: 28, class: 'form-control'
      .form-group
        %p.text-muted Click to upload new icon.
        .fileinput.fileinput-new{"data-provides" => "fileinput"}
          %div
            .fileinput-thumbnail.thumbnail{style: 'max-width: 100%;'}
              .fileinput-preview{data: {trigger: "fileinput"}, style: 'max-width: 100%;'}
                = image_tag @firms.try(:logo).try(:present?) ? @life_event.try(:logo).try(:url) : asset_path('/path.svg')
          %div
            %span.btn.btn-default.btn-file.btn-sm{style: 'display: none;'}
              = f.file_field :logo, class: 'file'
              = f.hidden_field :logo_cache
      .form-group
        = f.label :user_id
        = f.select :user_id,  User.all.collect {|u| [#{u.email}", u.id] }

        = f.submit class: 'btn btn-primary btn-sm'

In the create action you never set update the parameters on the model 在创建操作中,您永远不会设置更新模型上的参数

def create
  @paths = Path::Account.new(path_params)
  if @paths.save
    redirect_to system_path_creations_path(@paths)
  end
end

you will also need to add 您还需要添加

def path_params
  params.require(:path_account).permit(:name, :slug, :other, :params, :to, :permit)
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM