Use devise invitable with more than one type of user

434 Views Asked by At

I'm still struggling to do something but I have not accomplished much (I'm new to Ruby and Rails), what I have to do is implement 3 types of users for my project (admin, role1 and role2), where each one has different views and can do different stuff.

My user model is the devise user model, in which I added an attribute called "role" to distinguish them from each other, so for example, on my Admin controller I have:

class AdminController < ApplicationController
    before_filter :authenticate_user!
    before_filter :admin_only

...

before_filter :admin_only

  def admin_only
    unless current_user.role == "Admin"
        redirect_to :back
    end
  end
end

I hope I'm doing this right...

I'm also using devise_invitable to make the Admin register new users through an invitation by mail, the only thing I'm missing for the authentication and registration of new users to stay the way I want is to change the attribute "role" when I register a new user, this have to be role1 if I send the invitation from an specific path, and role2 if I send the invitation from another path, so, what I have on the view of the registration of users that have the role1 is like this.

<div class="container">

<p>Input the email of the new user.</p>

<%= form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => {:method => :post} do |f| %>
  <%= devise_error_messages! %>

  <% resource.class.invite_key_fields.each do |field| -%>
    <p><%= f.label field %><br />
    <%= f.text_field field %></p>
  <% end -%>

  <p><%= f.submit t("devise.invitations.new.submit_button") %></p>
<% end %>

I don't know what to do to accomplish this, can someone help me?

0

There are 0 best solutions below