,ruby-on-rails,nomethoderror"/>

首页 > 解决方案 > 未定义的方法 `ceo_name=' for #

问题描述

说“我想将我的数据保存在数据库中,但是两个控制器都发生了一个错误。

这是我的控制器代码.....

class ChiefexecutiveofficerController < ApplicationController
def new

end
def index
    @chiefexecutiveofficer = Chiefexecutiveofficer.all
end
def create

    @chiefexecutiveofficer = Chiefexecutiveofficer.new()
    @chiefexecutiveofficer.ceo_name = params[:chiefexecutiveofficer][:ceo_name]
    @chiefexecutiveofficer.ceo_pin = params[:chiefexecutiveofficer][:ceo_pin]
    @chiefexecutiveofficer.ceo_address = params[:chiefexecutiveofficer][:ceo_address]
    @chiefexecutiveofficer.ceo_salary = params[:chiefexecutiveofficer][:ceo_salary]



    if @chiefexecutiveofficer.save
         flash[:notice]= " Your CEO Record Is Successfully Created"
            redirect_to  welcome_index_path
    else

        flash[:notice]= " Your CEO record Is Not Created"
            redirect_to  welcome_index_path
    end 
end



private

def my_params
    params.require(:chiefexecutiveofficer).permit(:ceo_name,:ceo_name,:ceo_address,:ceo_salary)

end

end

标签: ruby-on-railsnomethoderror

解决方案


推荐阅读