Skip to content

Instantly share code, notes, and snippets.

@jms
Last active December 29, 2015 14:18
Show Gist options
  • Select an option

  • Save jms/7682591 to your computer and use it in GitHub Desktop.

Select an option

Save jms/7682591 to your computer and use it in GitHub Desktop.
command line
---------------------------------
padrino g project achiever -d none -t rspec -s none -e erb -c none -m none -b
padrino g controller Admin get:index get:new post:create
padrino start #defaults, non daemonized
padrino start -d -p 3000 -e development #daemonized, port 3000, specified env
padrino
padrino rake spec
padrino rake routes
logging
---------------
#boot.rb
Padrino::Logger::Config[:development][:stream] = :to_file
Padrino.load!
#usage
logger.info "foo"
#also available: fatal, error, warn, debug
stylesheet/javascript/favicon tag generation:
---------------------
<%= javascript_include_tag 'foo_js' %>
<%= stylesheet_link_tag 'foo_css' %>
<%= favicon_tag 'images/favicon.png' %>
# feed_tag also available
sections
-------------------------
<% content_for :blah do %>
foo bar baz
<% end %>
<div>
<%= yield_content :blah %>
</div>
form/html helpers
--------------------------
<%= link_to "Code Critic", url_for(:main, :index) %>
input_tag :text, :class => "demo" # => <input type='text' class='demo' />
form_tag '/destroy', :class => 'destroy-form', :method => 'delete' do
end
escape_html('<foo>abc</foo>')
pluralize(2, 'person') # '2 people'
word_wrap('foo bar baz', :line_width => 4)
truncate('foo bar baz', :length => 9) # foo bar ba ...
truncate_words('foo bar baz', :length => 2) # foo bar ...
strip_tags('<foo>abc</foo>') #abc
distance_of_time_in_words(2800.days.ago) # 'over 7 years'
distance_of_time_in_words(5.minutes.ago) # '5 minutes'
time_ago_in_words(2.days.ago) # '2 days'
time_ago_in_words(1.day.from_now) # 'tomorrow'
view rendering
------------------------
render :erb, 'path/to/erb/template'
render 'path/to/erb/template'
partial 'foo/bar', :collection => @photos
partial 'foo/baz', :object => @photo
layout :main_layout
render :erb, 'path/blah', :layout => :main_layout
controllers and routing
------------------------
http://www.padrinorb.com/guides/controllers
Active Record Task (ORM)
------------------------
rake ar:abort_if_pending_migrations # Raises an error if there are pending migrations.
rake ar:auto:upgrade # Uses schema.rb to auto-upgrade.
rake ar:charset # Retrieves database charset.
rake ar:collation # Retrieves databsae collation.
rake ar:create # Creates the database as defined in config/database.yml
rake ar:create:all # Creates local databases as defined in config/database.yml
rake ar:drop # Drops the database for the current Padrino.env
rake ar:drop:all # Drops local databases defined in config/database.yml
rake ar:forward # Pushes the schema to the next version.
rake ar:migrate # Migrates the database through scripts in db/migrate.
rake ar:migrate:down # Runs the "down" for a given migration VERSION.
rake ar:migrate:redo # Rollbacks current migration and migrates up to version
rake ar:migrate:reset # Resets your database using your migrations.
rake ar:migrate:up # Runs the "up" for a given migration VERSION NUMBER
rake ar:reset # Drops and recreates the database using db/schema.rb.
rake ar:rollback # Rolls back the schema to previous schema version.
rake ar:schema:dump # Creates a portable db/schema.rb file.
rake ar:schema:load # Loads a schema.rb file into the database.
rake ar:schema:to_migration # Creates a migration from schema.rb
rake ar:schema:to_migration_with_reset # Creates a migration and resets the migrations log.
rake ar:setup # Creates the database, loads the schema, and seeds data.
rake ar:structure:dump # Dumps the database structure to a SQL file.
rake ar:version # Retrieves the current schema version number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment