Skip to content

Instantly share code, notes, and snippets.

View kylemacey's full-sized avatar
💻
Writing bunches of code and stuff

Kyle Macey kylemacey

💻
Writing bunches of code and stuff
View GitHub Profile
@kylemacey
kylemacey / save.sublime-snippet
Created June 5, 2013 20:43
Handy snippet for responding in your `create` methods
<snippet>
<content><![CDATA[
respond_to do |format|
if @${1:${TM_FILENAME/(.*?)(s?)(_controller\..+)/$1/}}.save!
format.html { redirect_to @${1:${TM_FILENAME/(.*?)(s?)(_controller\..+)/$1/}}, notice: "${2:${TM_FILENAME/(.*?)(s?)(_controller\..+)/\u$1/}} has been saved successfully" }
format.json { render json: @${1:${TM_FILENAME/(.*?)(s?)(_controller\..+)/$1/}} }
else
format.html { render action: "new" }
format.json { render json: @${1:${TM_FILENAME/(.*?)(s?)(_controller\..+)/$1/}}.errors, status: :unprocessable_entity }
end
@kylemacey
kylemacey / placehold_it.rb
Created April 1, 2013 18:57
Paperclip interpolator to use http://www.placehold.it for default image
Paperclip.interpolates(:placehold_it) do |attachment, style|
# assumes using dimensions specified as integer, eg "250x250#"
params = attachment.styles[style][:geometry].match(/\d+x\d+/).to_s + "&text=#{attachment.instance.name}"
"http://www.placehold.it/" + params
end