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
| // Tudo FALSE | |
| if(null) | |
| echo 'NULL'; | |
| if(0) | |
| echo '0'; | |
| if(false) | |
| echo 'FALSE'; | |
| if("") | |
| echo 'VAZIO'; | |
| if(array()) |
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
| fonte: http://fernandoluizao.wordpress.com/2009/08/12/rails-otimizando-sti-com-default_scope/ | |
| Não dá pra negar que STI (Single Table Inheritance) é um recurso bacana do Rails. Claro que não é bom abusar, mas em alguns casos, ela se encaixa muito bem. No rails, quando queremos usar STI, basta ter uma coluna type do tipo string na tabela “mãe”, e nessa coluna o Rails se encarrega de gravar o nome da classe do registro, e a partir daí tudo funciona normalmente (para mais detalhes sobre como funciona STI no Rails, veja a api). Porém, apesar da implementação do Rails ser muito elegante e funcionar bem, ela tem alguns problemas: | |
| Comparações entre strings são lentas. Mesmo que haja um índice na coluna “type”, comparações entre strings ainda são bem mais lentas que comparações entre inteiros. | |
| Caso o model seja renomeado, os dados da coluna “type” terão que ser atualizados, ou ficaremos com dados incorretos na tabela. Para corrigir podemos criar uma migration, mas é mais uma coisa para se preocupar | |
| Vamos tentar mel |
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
| <div id="_guardaResultadoPesquisa"> | |
| <h2>Resultado da pesquisa</h2> | |
| <table cellspadding="0" cellspacing="0" width="100%"> | |
| <tr border="0"> | |
| <th width="14%"><span>Código</span></th> | |
| <th width="14%"><span>Nº</span></th> | |
| <th width="14%"><span>Nome</span></th> | |
| <th width="14%"><span>Data Vencimento</span></th> | |
| <th width="14%"><span>Status</span></th> |
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
| /* | |
| * Brincando com o placar do letsnode.com:8090 | |
| * | |
| */ | |
| function result(){ | |
| return eval(document.getElementById('operations').innerHTML); | |
| } | |
| function input_result() { |
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
| <script type="text/javascript"> | |
| // Substituir esse script: | |
| // https://github.com/kakobotasso/gvar/blob/master/app/views/financeiro/novo_pagamento.html.erb | |
| // | |
| // Depois colocar em um JS separado | |
| function get_tecla(e){ | |
| var tecla = (window.event) ? event.keyCode : e.which; | |
| return tecla; | |
| } |
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
| <!-- Antes --> | |
| <span> | |
| <% select_tag "release[instalments_attributes][#{count}][payment_id]", options_for_select(@payments,@release.instalments[count][:payment_id]), :class => 'select' %> | |
| </span> | |
| <!-- Depois --> | |
| <span> | |
| <%= i.select :payment_id, @payments, {}, :class => 'select' %> | |
| </span> |
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 Release < ActiveRecord::Base | |
| attr_accessible :category_id, :code, :description, :first_paid, :fixed_payment, :name, :number_instalments, :total_amount, :instalments_attributes | |
| has_many :instalments | |
| accepts_nested_attributes_for :instalments | |
| 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
| Instalment.joins(:release).where(:"releases.code" => "P1210040001") | |
| # ActiveRecord::Relation < Object |
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
| 11.2.1 Joining a Single Association | |
| Category.joins(:posts) | |
| This produces: | |
| SELECT categories.* FROM categories | |
| INNER JOIN posts ON posts.category_id = categories.id | |
| Or, in English: “return a Category object for all categories with posts”. Note that you will see duplicate categories if more than one post has the same category. If you want unique categories, you can use Category.joins(:post).select(“distinct(categories.id)”). | |
| 11.2.2 Joining Multiple Associations |
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
| var t = {} | |
| ,length = t.length | |
| // undefined | |
| length | |
| // undefined | |
| var t = {} | |
| ,length = t.length >>> 0 | |
| // undefined |