ruby on rails - How do I set up my model associations for an conference registration app? -



ruby on rails - How do I set up my model associations for an conference registration app? -

i've been playing around writing ror 4.2 app allow next behaviors:

admin users create list of conference courses include topic, description, etc conference attendees can register website , select conference courses they'd attend. conference attendees should not able create conference courses, select list of courses listed in database , select them attend. must way associate many users same course. when user selects course, seating capacity course of study should decremented (the details of aspect of solution secondary requirement @ time)

for sake of discussion, let's using devise user roles figured out , configured. have 1 user.rb model/table. created model/table called course.rb. created bring together model/table called course_selection.rb.

i configured these tables using has_many through associations bring together table belonging each so:

class user < activerecord::base has_many :course_selections has_many :courses, :through => :course_selections end class course of study < activerecord::base has_many :course_selections has_many :users, :through => :course_selections end class courseselection < activerecord::base belongs_to :user belongs_to :course end

i have set , able create new users, users non-admin roles able create courses (but haven't set kind of role based exclusions these users prevent them creating courses). when phone call restful route such http://localhost:3000/users/3/courses expecting see list of courses associated particular user. instead seeing courses listed in database.

my questions are:

can model associations strategy i've selected used accomplish behavioral goals i've specified? how controllers set user's course of study selection established, not using new/create methods create course? how forms set (i'm using simple_form) allow user select list of existing courses?

thanks help. haven't found tutorials seem address challenge.

can model associations strategy i've selected used accomplish behavioral goals i've specified?

yes, models fine start.

how controllers set user's course of study selection established, not using new/create methods create course?

the typical rails rest-like way have controller courseselectionscontroller manages association.

suppose have view page user can select course. view submit info courseselectionscontroller, params user_id , course_id. controller creates courseselection model, associates user , course.

the courseselectionscontroller have typical actions "create", "read", "delete". if course of study selection has other data, such price, or time slot, etc. there can action "update".

by way, in kind of application, middle model called enrollment instead of courseselection, , rest controller called enrollmentscontroller.

how forms set (i'm using simple_form) allow user select list of existing courses?

typically in app/views/course_selections. form based on courseselections (not users, , not courses). form shows list of courses. when user submits form, set (or post) courseselectionscontroller.

if want form able handle multiple courses, 1 way utilize ajax each course of study selected or unselected. way utilize multiple select fields, , create controller method can iterate on selected/unselected courses.

ruby-on-rails ruby activerecord

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -