Hi,
On Sun, Feb 12, 2017, at 18:22, Aida Delic wrote:
>
>
> Hi [image: :)]
>
>
>
> I'm new to Rails. I'm trying to make an app where students can login in
> and
> signup for the exam. I have a problem filtering data, where a student can
> only see exams which belong to her/his year and department.
>
>
>
> Subject has the following columns:
> t.string "name"
> t.integer "ects"
> t.integer "year"
> t.integer "professor_id" (foreign key which relates it to professor).
>
> Its relationship with exam:
> has_one :exam
>
> Exam has the following columns:
> t.date "start_date"
> t.string "department"
> t.integer "professor_id"
> t.integer "subject_id"
>
> Its relationship with exam:
> belongs_to :subject
>
> User has attributes year (year of study) and department. The problem is
> that exam only has depatment, but it doesn't have year.
>
> I have made this in exam.rb
>
> scope :department, -> (department) { where('department == ?', department)
> }
> scope :year, -> (year) { where('subject.year == ?', year) }
>
scope :year, -> (year) { where(subject: Subject.where(year: year)) }
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1486899368.4184564.878339664.27A2F050%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment