Skip to content

Instantly share code, notes, and snippets.

@jnx
Forked from mikeatlas/new_invitation.html.erb
Created May 7, 2014 12:56
Show Gist options
  • Select an option

  • Save jnx/942ddb377a0227dc2fe4 to your computer and use it in GitHub Desktop.

Select an option

Save jnx/942ddb377a0227dc2fe4 to your computer and use it in GitHub Desktop.

Revisions

  1. Mike Atlas revised this gist Jun 27, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion users_invitational_controller.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # /app/controllers/users_invitation_controller.rb
    # /app/controllers/users_invitations_controller.rb

    class UsersInvitationsController < Devise::InvitationsController

  2. Mike Atlas revised this gist Jun 27, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion users_invitational_controller.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # /app/controllers/users_invitational_controller.rb
    # /app/controllers/users_invitation_controller.rb

    class UsersInvitationsController < Devise::InvitationsController

  3. Mike Atlas revised this gist May 22, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion users.rb
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@

    collection_action :new_invitation do
    @user = User.new
    end
    end

    collection_action :send_invitation, :method => :post do
    @user = User.invite!(params[:user], current_user)
  4. Mike Atlas created this gist May 22, 2013.
    23 changes: 23 additions & 0 deletions new_invitation.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <!-- /app/views/admin/users/new_invitiations.html.erb -->

    <h2>Send invitation</h2>

    <%= form_for @user, :url => send_invitation_admin_users_path do |f| %>

    <table style='width: 50%'>
    <tr>
    <td><%= f.label :first_name %></td>
    <td><%= f.text_field :first_name %></td>
    </tr>
    <tr>
    <td><%= f.label :last_name %></td>
    <td><%= f.text_field :last_name %></td>
    </tr>
    <tr>
    <td><%= f.label :email %></td>
    <td><%= f.text_field :email, :required => true %></td>
    </tr>
    </table>

    <%= f.submit "Send an Invitation" %>
    <% end %>
    10 changes: 10 additions & 0 deletions routes.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    # /config/routes.rb

    devise_for :users,
    :controllers => {
    :sessions => "users_sessions",
    :registrations => "user_registrations",
    :passwords => "user_passwords",
    # Proper invitations should be sent through the active_admin interface.
    :invitations => 'users_invitations' # user_invitations_controller.rb
    }
    21 changes: 21 additions & 0 deletions users.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # /app/admin/users.rb

    action_item do
    link_to 'Invite New User', new_invitation_admin_users_path
    end

    collection_action :new_invitation do
    @user = User.new
    end

    collection_action :send_invitation, :method => :post do
    @user = User.invite!(params[:user], current_user)
    if @user.errors.empty?
    flash[:success] = "User has been successfully invited."
    redirect_to admin_users_path
    else
    messages = @user.errors.full_messages.map { |msg| msg }.join
    flash[:error] = "Error: " + messages
    redirect_to new_invitation_admin_users_path
    end
    end
    24 changes: 24 additions & 0 deletions users_invitational_controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    # /app/controllers/users_invitational_controller.rb

    class UsersInvitationsController < Devise::InvitationsController

    # GET /resource/invitation/accept?invitation_token=abcdef
    def edit
    render :edit, :layout => false
    end

    # PUT /resource/invitation
    def update
    self.resource = resource_class.accept_invitation!(resource_params)

    if resource.errors.empty?
    flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
    set_flash_message :notice, flash_message
    sign_in(resource_name, resource)

    redirect_to '/profile', :alert => "Welcome! Please fill out your profile and upload a headshot."
    else
    respond_with_navigational(resource){ render :edit, :layout => false }
    end
    end
    end