我在app / views / school / teachers / _sub_tabs.html.haml文件中有部分内容。我在app / views / school / teachers / form.html.haml中渲染了这个部分,它完美无缺。但是当我尝试在components / student / app / views / subjects / students / index.html.haml中渲染它时,它会给出错误:No route matches {:action=>"show", :controller=>"school/teachers", :id=>nil} missing required keys: [:id]
错误:
#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]
它在行“add_names”选项卡上给出错误
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]
在这里@resource
可以是teacher
或student
。
components/student/app/views/subjects/students/index.html.haml
:.col-xs-12.well-bordered = render 'school/teachers/sub_tabs', { selected_tab: { setting: 'selected' } }
我认为它无法在@teacher
找到subject/students
。但我已经在Subjects::Students
控制器中返回动作:
def find_resource @resource = if params[:teacher_id] teacher.find(params[:teacher_id]) else @student end end
路线如下:
scope '/school' do resources :teachers, module: :school namespace :subjects do resources :students end end
当我检查时,传递的资源是student
而不是teacher
。如何通过qazxswpoi对象? teacher
和Names
都属于Subjects
。
谢谢
编辑1:
我试图在路径中传递teacher
对象:
#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]
但即便如此,老师在@teacher
控制器中也没有。现在我得到的错误是:
Not found
在你的部分你有Subjects::Students
但在你的控制器中你只是将变量分配给@teacher
。添加teacher
!
编辑:另外,当你渲染部分时,你可以通过@
像这样:@teachers
在部分你可以用= render 'school/teachers/sub_tabs', { teachers: @teachers, selected_tab: { setting: 'selected' } }
访问它。