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
| class Brand < ActiveRecord::Base | |
| has_many :car_models | |
| end | |
| class CarModel < ActiveRecord::Base | |
| has_many :production_years | |
| belongs_to :brand | |
| end | |
| class ProductionYear < ActiveRecord::Base |
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
| 1) Simple: rake routes| grep -e foo | |
| 2) Compuesta de varias: | |
| 2.1) rake routes|egrep "(foo|bar)" | |
| 2.2) rake routes| grep -e foo -e bar |
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
| mysql -u root -p MYDATABASE -e "select * from products" -B > fichero33.csv | |
| o en consola podemos utilizar \T: | |
| select * from products \T resultadoooooooo.sql; |
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
| SELECT * | |
| FROM mi_tabla | |
| WHERE condicion | |
| -- Aqui formato de exportación | |
| INTO OUTFILE | |
| '/tmp/fichero_salida.csv' | |
| FIELDS TERMINATED BY ';' |
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
| # right expression, match | |
| str = "12345" | |
| eval = str.match /\A\d+\z/ | |
| puts eval ? 'match' : 'no match' | |
| # right expression, no match | |
| str = "hello123world" | |
| eval = str.match /\A\d+\z/ | |
| puts eval ? 'match' : 'no match' | |
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
| SchemaPlus::ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do | |
| def included(base) #:nodoc: | |
| base.alias_method_chain :initialize, :schema_plus | |
| end | |
| def initialize_with_schema_plus(*args) #:nodoc: | |
| initialize_without_schema_plus(*args) | |
| adapter = case adapter_name | |
| # name of MySQL adapter depends on mysql gem | |
| # * with mysql gem adapter is named MySQL |
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
| #These Ruby OOP examples, are based on the Rails 3 presentation by @guilhermecaelum | |
| class Person | |
| #the attribute name is immutable | |
| def initialize(name) | |
| @name = name | |
| end | |
| def name | |
| @name | |
| end | |
| end |
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
| # Put this in your ~/.irbrc for easy rails route scanning | |
| # | |
| # Usage: | |
| # > routes | |
| # => prints all routes | |
| # > routes /GET.*user/i | |
| # => prints routes matching a given regex | |
| # > routes "user" | |
| # => matches strings as well |
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
| class Ability | |
| include CanCan::Ability | |
| def initialize(user) | |
| user ||= User.new # guest user | |
| if user.role? :admin | |
| can :manage, :all | |
| else | |
| can :read, :all |
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
| PRJ=$HOME/Proyectos | |
| function goto | |
| { | |
| case $1 in | |
| (mipr) cd $PRJ/miproyecto1;; | |
| (pr) cd $PRJ;; | |
| esac | |
| pwd | |
| } |