Last active
December 13, 2015 17:09
-
-
Save prcaen/4945864 to your computer and use it in GitHub Desktop.
Rails tips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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