Skip to content

Instantly share code, notes, and snippets.

Student.find_or_create_by_name("Little Johnny DropTable")
Student.find_or_create_by_name_and_grade("Sally Sue", 5)
Student.where(name: "Little Johnny DropTable").first_or_create
# => <Student id: 1, first_name: 'Little Johnny DropTable', grade: 2>
Student.where(name: "Sally Sue", grade: 5).first_or_create
# => <Student id: 2, first_name: 'Sally Sue', grade: 5>
<!-- app/views/stores/show.html.erb -->
<% cache ["v3", @store] do%>
<h1>Store: <%= @store.name %></h1>
<%= render @store.employees %>
<% end %>
<!-- app/views/employees/_employee.html.erb -->
<% cache ["v3", employee] do %>
<div class='employee'>
<% # app/views/stores/show.html.erb %>
<% cache ["v3", @store] do%>
<h1>Store: <%= @store.name %></h1>
<%= render @store.employees %>
<% end %>
<% # app/views/employees/_employee.html.erb %>
<% cache ["v3", employee] do %>
<div class='employee'>
<% # app/views/stores/show.html.erb %>
<% cache @store do%>
<h1>Store: <%= @store.name %></h1>
<%= render @store.employees %>
<% end %>
<% # app/views/employees/_employee.html.erb %>
<% cache employee do %>
<div class='employee'>
class Store < ActiveRecord::Base
has_many :employees
end
class Employee < ActiveRecord::Base
belongs_to :store, touch: true
end
<% @agency.actions.sort_by { |action| -action.payment }.each do |action| %>
<% cache [action, action.lobbyist_actions, action.lobbyists, action.agency_actions, action.agencies] do %>
<tr>
<td><%= action.purpose %></td>
<td valign="top"> <% action.lobbyists.each do |lobbyist| %>
<%= link_to lobbyist.name, lobbyist_path(lobbyist.slug) %> <br>
<%end%>
</td>
<td valign="top"> <%= link_to action.client.name, client_path(action.client.slug) %> </td>
<td valign="top">$<%= action.payment %></td>
#source https://github.com/rails/rails/issues/10894
module ActiveSupport
module Cache
class FileStore < Store
private
# Patch this so we don't have long paths
def key_file_path(key)
fname = URI.encode_www_form_component(key)
hash = Zlib.adler32(fname)
class Application < ActiveRecord::Base
def self.model_call_setters
Agency.call_solo_payments
Agency.call_group_payments
Agency.set_sum_payments
Lobbyist.call_team_payments
Lobbyist.call_my_payments
Lobbyist.set_sum_payments
task :environment => :disable_initializer
task :disable_initializer do
ENV['DISABLE_INITIALIZER_FROM_RAKE'] = 'true'
end