Skip to content

Instantly share code, notes, and snippets.

@Hakon
Hakon / lyrics.rb
Created September 10, 2012 20:25 — forked from clarkware/lyrics.rb
Random Lyrics
#!/usr/bin/env ruby
# API Documentation at http://api.wikia.com/wiki/LyricWiki_API
require 'open-uri'
require 'json'
require 'tmpdir'
def itunes_song
`osascript -e 'tell application "iTunes" to (get name of current track) & "\n" & (get artist of current track)' 2>/dev/null`.split("\n")
@Hakon
Hakon / _form.html.erb
Created September 5, 2011 07:11 — forked from vjm/_form.html.erb
CRUD Devise Example
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
# this one does NOT work
params[:wine] = {:bulk_price_per_dozen => 50}
@wine = Wine.new(params[:wine])
# this one ALSO does NOT work
@wine = current_seller.wines.build(params[:wine])
# this one does work
@wine = current_seller.wines.build
@wine.attributes = params[:wine]
@Hakon
Hakon / additional notes
Created August 14, 2011 14:49
restrict deleting/updating to signed in users
I have a session variable that is created on login called current_user i can access the company id and user id by calling the following: current_user.company_id and current_user.id