samedi 11 septembre 2021

how can update the value of null column in rails

I am trying to create multiple bug against one project, but it show the error in edit_task_params

  param is missing or the value is empty: project

when i create the project the bug_id is null i just want to add bug ids against the project but i don't know how can i fix this issue .

project model

class Project < ApplicationRecord
   has_many :bugs
end

bug model class Bug < ApplicationRecord belongs_to :project end

bug_controller

class BugController < ApplicationController
    
    def new
      @bug = Bug.new
    end

    def create

      parameters = bug_params.merge({ user_id: current_user.id })   

      @bug = Bug.new(parameters)
      parameter = edit_task_params.merge({ bug_id: @bug.id })
      @project = Project.find(params[:project_id])
      @project = Project.update( parameter)
      respond_to do |format|
        if @bug.save
          @project = Project.find(params[:project_id])
          @project.update(edit_task_params)
          format.html { redirect_to new_bug_path, flash: { success: "bug added"} }
        else
          format.html { render :new }
        end
      end
   end

 private
 def bug_params
     params.require(:bug).permit(:title, :description, :screen_shot, :typeOf, :status_is, :deadline, :user_id, :project_id )
 end

 def edit_task_params
     params.require(:project).permit(:bug_id)
 end

end

Aucun commentaire:

Enregistrer un commentaire