我去时回滚 创建一个教学大纲

贾马尔

通过终端,我可以制作 CRUD 教学大纲,但是当我通过我的程序界面进行制作时,它不允许我“创建”并进行回滚。如何调试这个?我试过很多方法,我不知道到底发生了什么。最奇怪的是,我总是设法通过终端来做到这一点。

我的控制器

    before_action :set_syllabus, only: [:show, :update, :destroy]

    def show
      if @syllabus
        scheduled_dates = JSON.parse @syllabus.scheduled_dates
        # interests_array = @syllabus.student_interests.pluck(:data)
        
        if current_student.status != "freemium"
          render json: {
            goal: @syllabus.goal,
            objective: @syllabus.objective,
            level: @syllabus.level,
            estimate: @syllabus.estimate,
            interests: @syllabus.interests,
            skills: @syllabus.skills,
            schedule: {
                dates: scheduled_dates,
                minutes: @syllabus.scheduled_minutes
            }
            # }.merge({:interests => interests_array })
          }
        else
          render json: {
            blocked: true,
            goal: @syllabus.goal,
            objective: @syllabus.objective,
            level: @syllabus.level,
            estimate: @syllabus.estimate,
            interests: @syllabus.interests,
            skills: @syllabus.skills,
            schedule: {
                dates: scheduled_dates,
                minutes: @syllabus.scheduled_minutes
            }
            # }.merge({:interests => interests_array })
          }
        end
      else
        render json: {
          errors: "Record not found."
        }, status: 404
      end
    end

    def create
      @syllabus = Syllabus.new(syllabus_params)

      if @syllabus.save
        render json: @syllabus.as_json, status: :created
      else
        render json: {
            errors: @syllabus.errors
          }, status: :unprocessable_entity
      end
    end

    def update
      if @syllabus.update(syllabus_params)
        render json: @syllabus.as_json(except: [:id]), status: :ok
      else
        render json: {
          errors: @syllabus.errors
        }, status: :unprocessable_entity
      end
    end

    def destroy
      if @syllabus.destroy
        render :no_content
      else       
        render json: { errors: 
        breweries.errors.full_messages 
        }, status: :unprocessable_entity
      end
    end
  
    private
  
      def set_syllabus
        @syllabus = Syllabus.find_by(student_id: params[:id])
      end



      def syllabus_params
        params.permit(
          :student_id,
          :objective,
          :level,
          :goal,
          :estimate,
          :interests,
          :skills,
          :scheduled_dates,
          :scheduled_minutes
        )
      end
  end```



```[619aec90-7658-4825-aebb-82fc7aecc978] Started POST "/api/v1/students/syllabus" for ::1 to 2021-08-05 14:35:52 -0300
[619aec90-7658-4825-aebb-82fc7aecc978] Processing by Api::V1::SyllabusController#create as HTML
[619aec90-7658-4825-aebb-82fc7aecc978] Parameters: {"student_id"=>52776, "level"=>"Basic", "objective"=>"Be able to travel more smoothly", "goal"=>"Advanced ", "estimate"=>14.625, "scheduled_dates"=>["dom", "sab"], "scheduled_minutes"=>200, "interests"=>["Sports", ""], "syllabus"=> {"student_id"=>52776, "objective"=>"Be able to travel more smoothly", "level"=>"Basic", "goal"=>"Advanced", "estimate"=>14.625, "scheduled_dates"= >["dom", "sat"], "scheduled_minutes"=>200, "interests"=>["Sports", ""]}}
[619aec90-7658-4825-aebb-82fc7aecc978] Unpermitted parameters: :scheduled_dates, :interests, :syllabus
[619aec90-7658-4825-aebb-82fc7aecc978] (0.4ms) BEGIN
[619aec90-7658-4825-aebb-82fc7aecc978] ↳ app/controllers/api/v1/syllabus_controller.rb:49
[619aec90-7658-4825-aebb-82fc7aecc978] Student Load (0.5ms) SELECT "students".* FROM "students" WHERE "students"."id" = $1 LIMIT $2 [["id", 52776], [" LIMIT", 1]]
[619aec90-7658-4825-aebb-82fc7aecc978] ↳ app/controllers/api/v1/syllabus_controller.rb:49
[619aec90-7658-4825-aebb-82fc7aecc978] (0.2ms) ROLLBACK
[619aec90-7658-4825-aebb-82fc7aecc978] ↳ app/controllers/api/v1/syllabus_controller.rb:49
[619aec90-7658-4825-aebb-82fc7aecc978] Completed 422 Unprocessable Entity in 541ms (Views: 0.1ms | ActiveRecord: 5.2ms)```
眼花缭乱

错误就在那里,unpermitted parameters您将需要添加require(:syllabus)强参数。

params.require(:syllabus).permit(
          :student_id,
          :objective,
          :level,
          :goal,
          :estimate,
          :skills,
          :scheduled_minutes
          interests: [],
          scheduled_dates: [],
        )

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

PHP的交易错误,我总是得到一个回滚错误

如何制作动画情节以在到达最后一个动画步骤时停止回滚?

使用嵌套表单创建用户时的Rails回滚

cftransaction无法在出错时回滚创建表

回滚Laravel中的一个特定迁移

当我创建一个ViewController时,不能同时选择“也创建一个xib”

按下创建按钮并获取值字段以将其插入到 form_for 时回滚事务

Angular:当我点击一个按钮两次时,我如何去不同的路线?

如果一次更新失败,我如何回滚所有内容?

当其中一项并行作业失败时,DataStage 回滚数据

当存储过程中的任何一条insert语句失败时,回滚整个txn

根据以下runDB的定义,第二个插入是否会在第一个插入失败时回滚?

回滚一个非常特殊的预览包,导致一个肮脏的项目

SQL Server:如果我在完成之前停止了一个长时间运行的更新,它将自动回滚吗?

Spring Transaction-当一个数据库更新失败时,自动回滚以前的数据库更新

我如何创建一个孩子?

当我去选择一个选项时,似乎无法使下拉菜单保持活动状态

使用THROW时,SQL Server回滚我的事务

当我点击创建按钮时,我正在尝试创建一个新的“Qradiobutton”

通过第一个对象在 C++ 中创建第二个对象时,第一个对象去哪里了?

如果表有多个 FOR INSERT 触发器,其中一个写入审计表,另一个执行回滚,则审计回滚

当堆栈创建/更新失败时,如何验证云形成堆栈是否启用了自动回滚?

春季批处理回滚所有块并一次写入一个文件

CentOS-每周运行异常,导致我的整个安装失败,如何回滚/恢复到一周?

我应该每次创建一个ArrayBuffer还是清除以前创建的一个?

当我去隐藏一行 QTableView 时,我可以重新计算 verticalHeader 吗?

创建一个带有另一个回调的回调函数

仅当我在一个线程中收到回调时才释放CountDownLatch

当我导航回React-Native的前一个屏幕时,状态是否重置?