Skip to content

Instantly share code, notes, and snippets.

@prcaen
Last active December 13, 2015 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prcaen/4945864 to your computer and use it in GitHub Desktop.
Save prcaen/4945864 to your computer and use it in GitHub Desktop.
Rails tips
## CONSOLE
# Routes for a controller
rake routes CONTROLLER=products
## CONTROLLER
# Redirect to referrer
redirect_to :back # raise RedirectBackError if no referer
# Before filter and after filter in a same method
around_filter
# Usefull plugin for params verification in action
Link: https://github.com/sikachu/verification
ex: verify :params => "admin_privileges", :only => :update_post, :redirect_to => { :action => "settings" }
## ACTIVE RECORD
# Update updated_at timestamp entry
product.touch
=> Set updated_at to now
# Get SQL query
User.first.to_sql
=> SELECT * FROM 'users' WHERE 'users'.'id' = 1
# Get tables list
conn.tables
=> ["schema_info", ...]
# Create table temporary wich only exist for the migrations.
:temporary => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment