0

问题描述

为什么这里说undefined method

问题出现的环境背景及自己尝试过哪些方法

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)
.parameters-area

.parameters
    %h4 Parameters
#parameters-panel
    = parentform.fields_for :model_params, parentform.object.model_params.sort_by{|o| o.name.to_s.downcase } do |t|
        .panel
            .row{data:{"parameter-root": 'true'}}
                .medium-11.columns
                    .row
                        .medium-11.columns
                            = t.input :name
                            = t.input :data_type,collection: ModelParam.data_types.keys.to_a, input_html: {data: {"root-type": 'true'}}
                                    

这是我的model_param数据定义的数据
class CreateModelParams < ActiveRecord::Migration[5.0]
def change

create_table :model_params do |t|
  t.string :name
  t.integer :data_type
  t.integer :model_id
  t.timestamps
end
add_index :model_params, :model_id

end
end

下面是我的controller

class ModelController < ApplicationController

skip_authorization_check

def index
    @hostname = request.host 
    @hostport = request.port.to_s
    @model = Model.all
    @user_relations =Relation.where(user_id: current_user)
    @p_id = get_project_id
end 

def new
    @model=Model.new
    @p_id=get_project_id
  end

def create
    @model = Model.new(m_params)
    if @model.name.strip.length != 0
        if @model.save
            redirect_to  project_model_index_path, notice: 'Model was successfully created.'
        else 
            render 'new'
        end
    else
        render 'new'
    end
end
    


def destroy
    
  end
    
end

def show 
    @hostname = request.host 
    @hostport = request.port.to_s

end

def update

end


def get_project_id
    params[:project_id]
end
    
def m_params
    params.require(:model).permit(:name,:description,:response, model_params_attributes: [:id, :name, :data_type, :_destroy])
end


def get_id
params[:id]

end

闻豪 10
2018-11-06 提问
0 个回答

撰写答案

推广链接