class InvitesController

Constants

INVITATIONS_DEFAULT_MESSAGE

Invitations message

Public Instance Methods

accept() click to toggle source

Method to accept the Invite and when user click accept it will redirect user to signup page.

# File app/controllers/invites_controller.rb, line 40
def accept
   @invite = Invite.find_by(invite_token: params[:id])
   unless @invite
     redirect_to root_path, alert: "Invalid URL." and return
   end
   @invite.accept!
   redirect_to root_path(invitation_token: @invite.invite_token)
end
create() click to toggle source

It will create Invite email for the mail Ids user entered and send mails to those Id for signup.

# File app/controllers/invites_controller.rb, line 21
def create
  @invite = Invite.new invite_params
  @invite.valid?
  unless @invite.errors.messages.has_key?(:invitee_emails)
    @emails = @invite.invitee_emails.split(',').map(&:strip).compact
    invitations = current_user.invites.where(accepted_at: nil, invitee_email: @emails)
    invites = Invite.create((@emails - invitations.map(&:invitee_email)).map {|e| {invitee_email: e}})
    invites.map(&:send_invitation_email)
    respond_to do |format|
      format.js {render 'create'}
    end
  else
    respond_to do |format|
      format.js { render partial: 'form', object: @invite, replace: 'form#new_invite'}
    end
  end
end
new() click to toggle source

Intialize new object for invite form.

# File app/controllers/invites_controller.rb, line 15
def new
  @invite = Invite.new
  render layout: false
end
show() click to toggle source

It render to invite form(i.e. It will ask user to invite his friend to signup and get paid 1$)

# File app/controllers/invites_controller.rb, line 9
def show
  @name = current_user.name
  @message = INVITATIONS_DEFAULT_MESSAGE
end