Class names are CamelCase
.
Methods and variables are snake_case
.
Methods with a ?
suffix will return a boolean.
# Doesn't work | |
<p> | |
<% case @request.author_hosted %> | |
<% when "yes" %> | |
The school <b>has</b> hosted an author before. | |
<% when "no" %> | |
The school <b>has not</b> hosted an author before. | |
<% end %> | |
</p> |
First, Create a folder inside of lib
called seeds
Put your CSV file example.csv
into the lib/seeds
folder. In the example below, the file is called real_estate_transactions.csv
Make sure you've created a resource with the appropriate columns to match your seed data. The names don't have to match up.
Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.
Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.
As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.
Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.
sudo apt-get install python-software-properties | |
sudo apt-get install software-properties-common | |
sudo add-apt-repository ppa:rwky/graphicsmagick | |
sudo apt-get update | |
sudo apt-get install graphicsmagick |
def current?(key, path) | |
"#{key}" if current_page? path | |
# We use string interpolation "#{key}" here to access the CSS classes we are going to create. | |
end | |
in the views | |
<li> | |
<%= link_to "Blog", posts_path, class: "#{current? "active", posts_path}" %> |
def self.import(file) | |
conn = ActiveRecord::Base.connection | |
rc = conn.raw_connection | |
rc.exec("COPY callers (your_attributes) FROM STDIN WITH CSV") | |
file = File.open("#{file.path}", 'r') | |
while !file.eof? | |
rc.put_copy_data(file.readline) | |
end |
class SubdomainPresent | |
def self.matches?(request) | |
request.subdomain.present? | |
end | |
end | |
class SubdomainBlank | |
def self.matches?(request) | |
request.subdomain.blank? | |
end |
class TenantMiddleware < Apartment::Elevators::Subdomain | |
def call(*args) | |
begin | |
super | |
rescue Apartment::TenantNotFound | |
Rails.logger.error "Error: Apartment Tenant Not found: #{Apartment::Tenant.current.inspect}" | |
return [404, {"Content-Type" => "application/json"},["Error => Tenant not found"]] | |
end | |
end |
# You can have Apartment route to the appropriate Tenant by adding some Rack middleware. | |
# Apartment can support many different "Elevators" that can take care of this routing to your data. | |
# Require whichever Elevator you're using below or none if you have a custom one. | |
# | |
# require 'apartment/elevators/generic' | |
# require 'apartment/elevators/domain' | |
require 'apartment/elevators/subdomain' | |
require 'rescued_apartment_middleware' | |
# |