Local transition error There is no error with the given value (yield) on find_each

I am trying to execute a list of records that are retrieved using find_each.

I configured my controller code in the response in the column , but I still get the error message "No block (exit)".

I'm just starting to work with Ruby and Rails, and I have not yet found a full explanation (at least a few basic examples) of the blocks and lessons that give me what I need.

My code is as follows:

def select_save
    @class = params[:class]
    @student_id = params[:id]
    @class.each do |id|
      old_subject = Subject.find(id)
      new_subject = old_subject.dup
      new_subject.student_id = @student_id
      new_subject.save
      Assignment.find_each.where(:subject_id => id) do |assignments|
        assignments.each do |a|
          new_assignment = a.dup
          new_assignment.subject_id = new_subject.id
          new_assignment.save
        end
      end
    end

    respond_to do |format|
      format.html { redirect_to @student, :notice => 'Subject and assignments created.' }
    end
  end

and the error points to a string using find_each.

I know that I need a block to give way, but how exactly this will look in this particular case, it will elude me.

Thanks for any suggestions.

+5
source share
1

where find_each. . find_each where , , :

Assignment.find_each.where(:subject_id => id) do |assignments|

:

Assignment.where(:subject_id => id).find_each do |assignments|

, assignments, . find_each , . :

Assignment.where(:subject_id => id).find_each do |assignment|
  new_assignment = assignment.dup
  new_assignment.subject_id = new_subject.id
  new_assignment.save
end

, , subject_id Assignment. , :

old_subject.assignments.each do |assignment|
  new_assignment = assignment.dup
  new_assignment.subject_id = new_subject.id
  new_assignment.save
end
+5

All Articles