2017-06-13 31 views
0

我是新来的铁轨。我无法理解错误是什么以及如何解决它。 错误是PARAM缺失或为空值:学生错误:“param丢失或值为空:学生”

的form_for helper`

<%= form_for :students, :url=>{:action=>'create'} do |f| %> 

斯特朗参数

params.require(:students).permit(:s_name,:batch,:roll_no,:branch,:gender,:date_of_birth,:contact_no_1,:contact_no_2,:email,:spi_1,:spi_2,:spi_3,:spi_4,:spi_5,:spi_6,:spi_7,:cpi_7,:percent_10,:percent_12) 
end 

回答

0

尝试以下代码:

学生控制器

def new 
    @student = Student.new 
end 

def create 
    @student = Student.new(student_params) 
    @student.save 
end 

def student_params 
    params.require(:students).permit(:s_name,:batch,:roll_no,:branch,:gender,:date_of_birth,:contact_no_1,:contact_no_2,:email,:spi_1,:spi_2,:spi_3,:spi_4,:spi_5,:spi_6,:spi_7,:cpi_7,:percent_10,:percent_12) 
end 

视图

<% form_for @student do |f| %> 
    ... 
<% end %> 
1

如果你检查,你会发现,你的参数都没有这种形式的PARAMS

{students: {'s_name': 'xyz', 'batch': 'cse'}} 

这意味着以前的答案这是由@puneet解释是制作CRUD的最佳方法试试这种方式。

相关问题