2017-06-13 27 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的最佳方法試試這種方式。

相關問題