Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Jamie Wilkinson http://tramchase.com

« Newer Snippets
Older Snippets »
4 total  XML / RSS feed 

Ubuntu 7.10: bootstrap a Ruby on Rails stack

// get started with ubuntu 7.1
// e.g. on a new slice from http://slicehost.com !

# 1) make yrself a user and stop being root

# 2) main web stack + ruby
sudo aptitude install -y make screen
sudo aptitude install -y apache2 php5 mysql-server
sudo aptitude install -y subversion postfix
sudo aptitude install -y ruby1.8 ruby1.8-dev rubygems irb
sudo aptitude install -y imagemagick librmagick-ruby1.8 librmagick-ruby-doc libfreetype6-dev xml-core

# 3) gemz
# rubygems appears to be broken as hell. 
# gem update --system does squat
# had to manually d/l rubygems 1.0.1, ruby setup.rb
wget http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz
tar xzvf rubygems-1.0.1.tgz
cd rubygems-1.0.1
sudo ruby setup.rb
sudo gem install rails mongrel merb map_by_method


jQuery and Rails' respond_to

// Just throw this at the bottom of your application.js and you’re good to go: all jQuery ajax requests will trigger the wants.js block of your respond_to declaration, exactly like you’d expect. Enjoy.
// via: http://ozmm.org/posts/jquery_and_respond_to.html

jQuery.ajaxSetup({beforeSend’: function(xhr) {xhr.setRequestHeader(“Accept”,text/javascript”)} })

Never render the full layout in a Rails view when called via AJAX

Essential for degradable javascript, when one never knows if a view or partial is being called via XmlHttpRequest or not. Throw the below code in your ApplicationController (application.rb)

More info in this blog post

def render(*args)
        args.first[:layout] = false if request.xhr? and args.first[:layout].nil?
        super
end

ajax_request? method to XHR detection

A oneline helper I put in all of my apps. Looks for HTTP headers that signal you're being called via an XmlHttpRequest. I use it for instant degradable AJAX by rendering a template if it's as usual but just rendering a partial if they just want that part!

  def ajax_request?
    request.env['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' || params[:ajax]  # params[:ajax] for safe-keeping, FIXME if it works w/ all browsers
  end
« Newer Snippets
Older Snippets »
4 total  XML / RSS feed