Skip to content

Instantly share code, notes, and snippets.

# app/views/posts/new.html.erb
<%= form_for(Post.new) do |form| %>
Title: <%= form.text_field :title %>
Body: <%= form.text_field :body %>
<% end %>
...would produce a signature field that can be used to automatically untaint:
<input type="hidden" name="signature" value="....">
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
Hi David,
My name is Jeff Morse. I'm a Recruiter at a super-charged start-up called Mixbook www.mixbook.com I came across your profile on workingwithrails and have a full-time Sr. Ruby on Rails opening working onsite in our Palo Alto, California office that is a great match for your background/experience. Would you be ready to make the move to Silicon Valley, the most innovative place for web start ups which offers superior growth opportunities for talented ruby developers like yourself? Mixbook will pay for all relocation costs.
Would you be open to taking a phone/Sykpe call from our CTO, Aryk Grosz (see attached LinkedIn profile) to discuss the position further? If interested, email me your Skype ID and I’ll coordinate the call with Aryk.
Cheers,
Jeff Morse
Sr. Recruiter
Hi David,
I came across your profile online and wanted to reach out about Development
Opportunities here at Groupon. The company is growing, and we're always
looking for folks with solid skills that can make positive contribution to
our continued success. Any chance you'd be open to a quick conversation
about opportunities, or for any possible networking potential? If so, let me
know when you're free and we can set up a time to chat. Also, if you are
interested, it would be great if you could forward a current resume over
that I can take a look at. I look forward to hearing back from you! Please
let me know if you have any questions.
def revoke(user)
proxy_association.owner.tap do |project|
# You can't remove the last user with access (someone has to have access to the project!)
if project.users.many?
if user.pending? && user.projects.one?
user.destroy
else
project.users.delete(user)
user.touch
end
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@dhh
dhh / gist:981520
Created May 19, 2011 19:27
bulk api
# Bulk API design
#
# resources :posts
class PostsController < ActiveController::Base
# GET /posts/1,4,50,90
# post_url([ @post, @post ])
def show_many
@posts = Post.find(params[:ids])
end
@dhh
dhh / gist:966615
Created May 11, 2011 14:59
Database design snapshots
Designers need fleshed out pages to do properly design a screen.
In the past, we've loaded test fixtures in development to give them that.
But test fixtures are not a good fit for this.
They're designed to make testing easy, not designing.
What we need instead is a way for a designer to create a dataset
that'll work great for design and then save that as a snapshot.
This snapshot can be named and reloaded as often as desired.
I envision it'll work like this:
@dhh
dhh / gist:966575
Created May 11, 2011 14:43
Mailbag feature
class NotesController < ApplicationController
def create
@note = @project.notes.create params[:note].merge(
creator: current_user, subscribers: extract_subscribers(params[:note]))
@note.subscribers.each { |subscriber| Subscriptions.note(@note, subscriber).deliver }
end
end
class Subscriptions < ActionMailer::Base
@dhh
dhh / gist:965746
Created May 11, 2011 01:33
Pjax helper
module Pjax
extend ActiveSupport::Concern
included do
layout ->(c) { pjax_request? ? false : 'application' }
end
private
def redirect_pjax_to(action, url = nil)
new_url = url_for(url ? url : { action: action })