错误:" param丢失或值为空:学生"

时间:2017-06-13 05:26:11

标签: ruby-on-rails-4

我是铁杆新手。我无法理解错误是什么以及如何解决它。 错误 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

2 个答案:

答案 0 :(得分:1)

如果你检查参数,你会发现你的参数不是这种形式

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

这意味着@puneet解释的前一个答案是让 CRUD 尝试

的最好方法。

答案 1 :(得分: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 %>