0

Im new to ruby but trying to create a project, after doing some research i found to use Devise, cancan and role models, however im not having much luck and would really appreciate some assistance or guidance n where i can go to do this!

Basically i am trying to create a site which allows sports coaches/athletes to sign up, the coach can then set a different weekly program, of which the athlete will fill in daily, only on certain selected areas but can still veiw what the coach has written. of which then the coach can then print out the report from that week once the athlete has filled it in

I have installed devise, cancan and rolemodel, and got the basics set up using this http://www.phase2technology.com/blog/authentication-permissions-and-roles-in-rails-with-devise-cancan-and-role-model/ , however im struggling to see how i can sign the athletes up as "athletes" and coaches up as "coaches" even then only allowing coaches to select certain athletes (their athletes) to assign training programs to.

Thankyou your help would be most appreciated!

1 Answers1

0

I would use models based on some other, let's say User model, that has Devise mixed in. Then you could create Athlete and Coach models inherited from User.

In the view, you would just have to add new fields for registration (e.g. radio buttons to select between those two models). This will require a bit of changing the basic convention of Devise, but will save you a lot of time implementing 2 devise models separately.

konole
  • 766
  • 4
  • 8
  • Thanks Konrad, will give it ago! to create a new devise model is it 'rails g model coach'?? – user2278385 Apr 14 '13 at 15:59
  • 1
    You could also create a 'Group' model and assign the coaches to the group with a value of "Coaches" and "Athletes" to the group with a value of "Athletes". It's easy then to restrict access based on group appartenance (if user is member of group Coaches then he has ability to do A B C, if user is member of group Athletes he has abilities to do DEF), and you can refine with roles inside groups... – phron Apr 14 '13 at 16:29
  • phron - it's a good idea, if we plan to create more groups in a future. In other case, we can even use column named "type" and just put there either "athlete", or "coach". But this is nothing more than STI. – konole Apr 14 '13 at 20:20