$ rails g model User
belongs_to
has_one
http://guides.rubyonrails.org/migrations.html
-- show running queries (pre 9.2) | |
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query | |
FROM pg_stat_activity | |
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
ORDER BY query_start desc; | |
-- show running queries (9.2) | |
SELECT pid, age(clock_timestamp(), query_start), usename, query | |
FROM pg_stat_activity | |
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |
The default Postgresql installation on Mac OS X using homebrew includes a single extension - plpgsql (PL/pgSQL procedural language) but there are a number of them available in the lib directory (/usr/local/Cellar/postgresql/9.2.1/lib on my machine) | |
To install an extension into the database, the easiest way I found was to open a database console using the 'rails db' command and then create it directly. I have seen mention of doing this in a Rails migration but this did not work for me. | |
Note that an extension is installed in a specific database, rather than being added to all databases. | |
The command to list the installed extensions is '\dx' | |
$ rails db | |
psql (9.2.1) |
Cheat Sheets are greate but they are not a substitute for learning the framework and reading the documentation as we most certainly have not covered every potential example here. Please refer to the Rails Command Line Docs for more information.
You can get all of this information on the command line.
rails generate
with no generator name will output a list of all available generators and some information about global options.
rails generate GENERATOR --help
will list the options that can be passed to the specified generator.
# because i can never remember exactly how and when to use concat | |
# when building content in helpers | |
def nested_content | |
content_tag 'div' do | |
concat(content_tag 'span', 'span block') | |
concat(tag 'br') | |
concat(link_to 'root link', root_path) | |
concat(tag 'br') | |
concat(link_to('#') do | |
concat(content_tag 'h2', 'Head \'em off') |