0
votes

I have a partial in app/views/school/teachers/_sub_tabs.html.haml file. I rendered this partial in app/views/school/teachers/form.html.haml and it works perfectly. But when I try to render it in components/student/app/views/subjects/students/index.html.haml, it gives error : No route matches {:action=>"show", :controller=>"school/teachers", :id=>nil} missing required keys: [:id]

Error:

#tertiary-slider.pills-container

  %span

#tertiary-slider.pills-container
  %span
    = link_to t('.add_names'), teachers_path(@teacher), class: selected_tab[:add_names]
  %span
    = link_to t('.add_subject'),subjects_student_path(@resource), class: selected_tab[:add_subject]

It is giving error at line "add_names" tab

  1. app/views/school/teachers/_sub_tabs.html.haml :
#tertiary-slider.pills-container
  %span
    = link_to t('.add_names'), teacher_path(@teacher), class: selected_tab[:add_names]
  %span
    = link_to t('.add_subject'),subjects_student_path(@resource), class: selected_tab[:add_subject]

Here the @resource could be either teacher or student.

  1. components/student/app/views/subjects/students/index.html.haml:
.col-xs-12.well-bordered
  = render 'school/teachers/sub_tabs', { selected_tab: { setting: 'selected' } }

I think it cannot find the @teacher in subject/students. But I have return the action in Subjects::Students controller as:

    def find_resource
      @resource = if params[:teacher_id]
        teacher.find(params[:teacher_id])
      else
        @student
      end
    end

Routes are as:

    scope '/school' do
      resources :teachers, module: :school
      namespace :subjects do
        resources :students
      end
    end

When I inspected, the resource passed is student and not teacher. How to pass teacher object? Names and Subjects both belongs to teacher.

Thanks

EDIT 1:

I tried to pass the @teacher object in the path as:

#tertiary-slider.pills-container

  %span

#tertiary-slider.pills-container
  %span
    = link_to t('.add_names'), teachers_path(@teacher), class: selected_tab[:add_names]
  %span
    = link_to t('.add_subject'),subjects_student_path(@teacher), class: selected_tab[:add_subject]

But even then the teacher is going nil in Subjects::Students controller. And the error now I get is:

Not found
1

1 Answers

1
votes

In your partial you have @teacher but in your controller you're just assigning the variable to teacher. Add the @!

EDIT: Also, when you render the partial you can pass @teachers through like so: = render 'school/teachers/sub_tabs', { teachers: @teachers, selected_tab: { setting: 'selected' } } In the partial you can access it with teachers then.