Home > Software design >  Show students in particular standard in school Rails
Show students in particular standard in school Rails

Time:09-26

I have two different models one is "Standard" which has only a standard named attribute and a "Student" model which is inherited from user model which has standard attribute also . so here i want to show students on standard show page where Standard's->standard is == Student->standard,where 'standard' in students attribute is and part of serialise attribute which is named 'custom_attr' is an array

Edit

i have tried this in 'standard helper'

module StandardsHelper    
  def students_list
    User.where(role: "student")
  end
end

and tried in 'standards show'

<% if @standard.class_room %>
   <%= render 'users/students', users: students_list %>
<% end %>

here i created a partial file thats why i need to find users with role student in standard helper... but it is showing all students in one standard only,such as when i click on 12th standard it showing all students and when i click on 11th standard it is not showing any record...

thank you in advance for any help and advice....

Update I just want to show students when i click on 11th class then how will i extract students who are in 11th class from user database...

sorry , i know that my question is bit confusing so that's why i edited this... please help me for clear my confusion ...

CodePudding user response:

Can you try this?

User.where(role: "student").select{|user| user.custom_attr['standard'] == '11th'}

I hope this will help you

  • Related