Skip to content

Instantly share code, notes, and snippets.

@brandon-beacher
Created March 30, 2012 17:15
Show Gist options
  • Save brandon-beacher/2253047 to your computer and use it in GitHub Desktop.
Save brandon-beacher/2253047 to your computer and use it in GitHub Desktop.
ActiveRecord::Schema.define(:version => 20120330150918) do
create_table "users", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "email"
t.string "password_digest"
t.string "invitation_token"
end
end
AppName::Application.routes.draw do
resource :invitation
resource :rsvp
resource :sign_in
resource :sign_up
end
class InvitationsController < ApplicationController
def create
@user = User.find(params[:user_id])
@user.update_attributes!(
invitation_token: SecureRandom.hex(8))
UserMailer.invitation(@user).deliver
flash[:success] = "#{@user.name} was invited!"
redirect_to @user
end
end
doctype html
html
head
body
h1
| Hey #{@user.to_s}.
p
| You've been invited!.
p
| Click
= link_to "here", edit_rsvp_url(invitation_token: @user.invitation_token)
| to begin.
class RsvpsController < ApplicationController
def edit
@user = User.find_by_invitation_token!(
params[:invitation_token])
end
def update
@user = User.find_by_invitation_token!(
params[:invitation_token])
@user.attributes = params[:user]
@user.invitation_token = ""
if @user.save
sign_in @user
flash[:success] = "Welcome!"
redirect_to @user
else
render "edit"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment