2017-06-01 62 views
0

我有一个表单,我用于新建和编辑,以及索引和单击新功能的窗体和编辑工作,但是当我去创建或更新窗体返回一个加载错误到另一个控制器。无法自动加载常量控制器

控制器是系统中的PathCreationsController,它想在另一个地方使用创作控制器,它想用它来定义它......这很奇怪,因为我没有任何设置要做。

我试着向表单添加一个url并设置要放的方法,但是当我这样做并强制控制器正常工作时,它将数据库中的所有参数设置为null,所以我认为这不是一种有效的方法解决这个问题。

这里是控制器:

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 

这里是形式:

= 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' 

回答

0

在你从来没有设置更新参数型号

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

你会创建操作还需要添加

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

关于约定的一些注意事项 Rails寻找控制器(模型名称复数形式)给定模型名称的控制器,除非另有明确告知,所以对于模型路径控制器将是PathsController并且路径将沿着/路径/ 其次:对数组和集合使用复数参数和对单个对象使用单个时态参数的好习惯(即Path :: Account.all的路径,但Path :: Account.new的路径 这有助于了解识别变量中的内容。 –

+0

虽然这是正确的方式做到这一点,我现在得到的参数是空的地方 – codewarrior

+0

你可以添加一个日志文件的副本,显示请求中传递了什么参数? –

相关问题