Skip to content

Instantly share code, notes, and snippets.

@iHiD
Created May 7, 2012 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iHiD/2628630 to your computer and use it in GitHub Desktop.
Save iHiD/2628630 to your computer and use it in GitHub Desktop.
How to Build A Secure Website With Ruby On Rails
config.force_ssl = true
var form_data = //.. Serialise a form
// Get token and param from the meta tags
var token = $('meta[name="csrf-token"]').attr('content');
var param = $('meta[name="csrf-param"]').attr('content');
// Create url of "/settings/profile?name=Jeremy+Walker&authenticity_token=askdsalewg303y09sd00dshb0b00ac0dffbafds"
document.location = "/settings/profile?_method=PUT&" + form_data + "&" + token + "=" + param;
rails generate session_migration
rake db:migrate
heroku addons:add ssl:endpoint
heroku certs:add my_cerficate.crt site.key
Security::Application.config.session_store :active_record_store
# Authenticate user
@user = #...
# Destroy the existing session in case anyone is sharing it and
# create a new session that you know to be unique to the user.
reset_session
# Store the user's id as normal
session[:user_id] = @user.id
class SettingsController < ApplicationController
def show
@user = User.find(session[:user_id])
end
def update
@user = User.find(session[:user_id])
@user.update_attributes(params[:settings])
end
end
Security::Application.routes.draw do
match 'show_settings' => "settings#show"
match 'update_settings' => "settings#update"
end
Security::Application.routes.draw do
get 'show_settings' => "settings#show"
put 'update_settings' => "settings#update"
end
Security::Application.routes.draw do
resource :settings
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment