Created
March 30, 2012 17:15
-
-
Save brandon-beacher/2253047 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AppName::Application.routes.draw do | |
| resource :invitation | |
| resource :rsvp | |
| resource :sign_in | |
| resource :sign_up | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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