Skip to content

Instantly share code, notes, and snippets.

View tibra's full-sized avatar

Tim Brandes tibra

View GitHub Profile
@tibra
tibra / rails_3_1_beta_1_changes.md
Created May 21, 2011 18:13 — forked from ryanb/rails_3_1_rc4_changes.md
The Changelogs for Rails 3.1 Beta 1

Railties 3.1 Beta 1

  • The -j option of the application generator accepts an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". As of this writing "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline. Default is "jquery". [fxn]

  • jQuery is no longer vendored, it is provided from now on by the jquery-rails gem. [fxn]

  • Prototype and Scriptaculous are no longer vendored, they are provided from now on by the prototype-rails gem. [fxn]

  • The scaffold controller will now produce SCSS file if Sass is available [Prem Sichanugrist]

class ReportsController < ApplicationController
def index
@reports = Report.all
end
def show
@report = @technician.report.find(params[:id])
end
def new
@tibra
tibra / gist:816256
Created February 8, 2011 10:44
Trying to retrieve :shape in model
class UploadsController < ApplicationController
def create
...
@upload.shape = "photo"
...
if @upload.save
...
end
class Upload < ActiveRecord::Base
belongs_to :uploadable, :polymorphic => true
attr_accessible :uploadable_id, :uploadable_type, :attachment, :shape, :description
# Make :parent_type available for Paperclip :path & :url options.
# Path on S3 should contain the parent class (e.g. "member") for
# better readability.
Paperclip.interpolates :parent_type do |attachment, style|
Here we get :parent_type --> works √
Paperclip.interpolates :parent_type do |attachment, style|
attachment.instance.uploadable_type.downcase
end
Here, :parent_type works in :path => but not in Proc, how do I solve this?
has_attached_file :attachment,
:path => ":class/:parent_type/:id/:style.:extension",
@tibra
tibra / paperclip.rb
Created February 2, 2011 10:08
Should set default_options for paperclip for better DRY.
module Paperclip
class Attachment
def self.default_options
@default_options ||= {
:url => ":attachment/:id/:style.:extension",
:path => ":rails_root/public:url",
:s3_credentials => "#{Rails.root}/config/s3.yml",
:storage => :s3,
:styles => {},
:processors => [:thumbnail],
class Game < ActiveRecord::Base
has_many :photos, :as => :picturable, :dependent => :destroy
accepts_nested_attributes_for :photos, :allow_destroy => true, :reject_if => lambda { |a| a[:picture].blank? }
end
should be outsourced into a module like
=> /lib/attachment.rb
# Change prefix key to Ctrl+a
unbind C-b
set -g prefix C-a
# Last active window
unbind l
bind C-a last-window
# Copy mode
unbind [