SystemStackError, stack level too deep when trying to route to a controller in rails

The error says

SystemStackError in FacilitatorController index #

but this is not a problem with the controller because nothing happens if I change the lines there. He gets to the controller. I think this is probably a routing issue, but I'm not sure what is causing it.

Link

<%= link_to "Add Facilitators", facilitator_index_path(:course => @course.id), >:method => :get %>

      

Relevant routes

resources :facilitator
delete '/facilitator', to: 'facilitator#delete', as: 'facilitator_delete'

      

Some of the controllers

class FacilitatorController < ApplicationController
  def index
    @course = Course.find(params[:course])
    if params[:search_field]
      @user = User.select{|user| user.email.downcase.include? params[:search_field].downcase}
    else
      @user = User.where('id not in (?)', @course.facilitators)
    end
  end
end

      

I think it might have something to do with the Courses model having intermediaries via an alias and conflicting with the intermediary controller?

class Course < ActiveRecord::Base
...

  has_many :facilitate_ownedcourses, foreign_key: :ownedcourse_id
  has_many :facilitators, through: :facilitate_ownedcourses, source: :facilitator

      

Can anyone please help?

+3


source to share


2 answers


First, you have a typo in link_to

, should be :method

, and not>:method

Also in your controller

@user = User.select{|user| user.email.downcase.include? params[:search_field].downcase}

      

there should be something like



@user = User.all.select{|user| user.email.downcase.include? params[:search_field].downcase}

      

or better yet

@user = User.where('email like ?', "%#{params[:search_field].downcase}%")

      

To handle case

, you can change like

for ilike

if you are using postgres, or you can use lower(email)

if you are using mysql

0


source


First you have a syntax error in the Add Facilitators link, suggesting that it is typing an error.

Second, the way back will be helpful for a suggestion, but a couple of suggestions are below:



  • Check the callback of any user
  • The iterative method call can be during the before_action from the controller.
0


source







All Articles