I am trying to make an app with Rails 4. I use bootstrap, devise simple form and role_model gems.
profile.rb
class Profile < ActiveRecord::Base
include RoleModel
#reminder for roles (RoleModel): always add new roles to the end of this line - don't change the order
roles :admin, :manager,
:student, :educator, :researcher, :ktp, :faculty_manager, :ip_asset_manager,
:sponsor,
:project_manager, :representative, # for both uni and industry
:grantor, :investor, :adviser, :innovation_consultant, :panel_member,
:participant, :guest, :pending
# Other stuff goes here
end
Then in my profile view, I have a form where I ask users where they are from. I want to phrase the question differently depending on the user's role and I want to use a different array of options depending on that role. Eg, if the current user is a student, then the array should be populated with a list of universities.
<div class="col-md-3 col-md-offset-1">
<% if current_user.profile.has_any_role?(:student, :educator, :researcher, :ktp, :faculty_manager, :ip_asset_manager) %>
<%= f.label 'Select your university', :class => 'question-project' %>
<% elsif current_user.profile.has_role?(:sponsor) %>
<%= f.label 'Select your organisation', :class => 'question-project' %>
<% elsif current_user.profile.has_any_role?(:grantor, :investor, :adviser, :innovation_consultant, :panel_member) %>
<% end %>
</div>
<div class="col-md-7">
<div class="response-project">
<% if current_user.profile.has_any_role?(:student, :educator, :researcher, :ktp, :faculty_manager, :ip_asset_manager) %>
<%= f.collection_select :university_id, University.all, :id, :name, prompt: 'Select your university' %>
<% elsif current_user.profile.has_role?(:sponsor) %>
<%= f.collection_select :organisation_id, Organisation.all, :id, :name, prompt: 'Select your organisation' %>
<% elsif current_user.profile.has_any_role?(:grantor, :investor, :adviser, :innovation_consultant, :panel_member) %>
<%= f.collection_select :firm_id, Firm.all, :id, :name, prompt: 'Select your organisation' %>
<% else %>
<%= current_user.profile.id %>
<% end %>
I have the final else statement to prove that all of the above isn't working. When I try this, using the user with the role :student, should send me down the first route. It doesn't work. I get the user.profile.id instead.
Can anyone see what I have done wrong?