Skip to content

Instantly share code, notes, and snippets.

View tibra's full-sized avatar

Tim Brandes tibra

View GitHub Profile
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 [
@tibra
tibra / gist:ddb91a43857413f9009c
Created June 16, 2014 09:18
Include a LaTeX figure in Scrivener
<!--
\begin{figure}[htbp]
\centering
\setlength{\fboxsep}{0pt}%
\setlength{\fboxrule}{1pt}%
\fbox{\includegraphics[keepaspectratio,width=\textwidth,height=\dimexpr\textheight-2\baselineskip\relax]{../Grafiken/Grafik_Diagnostik_Erkenntnisinteresse.jpg}}
\caption{Erkenntnisinteressen der Diagnostik}
\label{grafik_diagnostik_erkenntnisinteresse}
\smallskip
\footnotesize