Skip to content

Instantly share code, notes, and snippets.

@metamn
metamn / base_template.rb
Created May 19, 2009 14:35
Basic Rails Application Template
# this is a basic rails application template
# usage: rails <app_name> -m http://gist.github.com/114140.txt OR rails -d mysql ....
puts ""
puts "*******************************************************"
puts ""
puts "Basic Rails application generator with:"
puts " - MySQL support (creating development, test and production databases with configuration file database.yml)"
puts " - HAML/SASS/Compass support"
puts " - BDD support: Cucumber, RSpec, autospec"
@metamn
metamn / cucumber.yml
Created May 19, 2009 15:26
Cucumber Config File
autotest-all: --require features --require lib --format progress features
autotest: --require features --require lib features
default: --format pretty
html: --format html --out features.html
@metamn
metamn / compass.config
Created May 19, 2009 16:31
Configuration answers when setting up Compass
y
n
@metamn
metamn / application.html.haml
Created May 19, 2009 16:35
HTML headers for HAML applications
!!!
%html{:xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en", :lang => "en"}
%head
= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
= stylesheet_link_tag 'print.css', :media => 'print'
/[if IE]
= stylesheet_link_tag 'ie.css', :media => 'screen, projection'
= stylesheet_link_tag 'application', :media => 'screen, projection'
%body.container
#header
@metamn
metamn / authentication_template.rb
Created May 19, 2009 17:36
Authlogic Rails template based on a basic template
# authentication based on authlogic
if yes?("Load the Basic Rails template?")
run "wget http://gist.github.com/114140.txt"
run "mv 114140.txt base_template.rb"
load_template "base_template.rb"
end
if yes?("(Re)Install Authlogic?")
run "sudo gem install authlogic"
@metamn
metamn / authentication_session_controller.rb
Created May 19, 2009 18:08
Controller code for Authlogic's UserSession model
class UserSessionsController < ApplicationController
before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => :destroy
def new
@user_session = UserSession.new
end
def create
@user_session = UserSession.new(params[:user_session])
@metamn
metamn / authentication_users_controller
Created May 19, 2009 18:12
Users Controller for Authlogic
class UsersController < ApplicationController
before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => [:show, :edit, :update]
def new
@user = User.new
end
def create
@user = User.new(params[:user])
@metamn
metamn / authentication_application_controller.rb
Created May 19, 2009 18:18
Application controller for Authlogic
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
filter_parameter_logging :password, :password_confirmation
helper_method :current_user_session, :current_user
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@metamn
metamn / auth_user_sessions_new.html.haml
Created May 19, 2009 18:25
Login view for Authlogic
= content_for :content do
%h1 Login
- form_for @user_session do |f|
= f.error_messages
= f.label :login
%br
= f.text_field :login
%br
%br
@metamn
metamn / auth_edit_user.html.haml
Created May 19, 2009 18:32
Edit User for Authlogic
= content_for :content do
%h1 Edit My Account</h1>
- form_for @user, :url => account_path do |f|
= f.error_messages
= render :partial => "form", :object => f
= f.submit "Update"
%br
= link_to "My Profile", account_path