This file contains 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 jq = document.createElement('script'); | |
jq.src = "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"; | |
document.getElementsByTagName('head')[0].appendChild(jq); | |
// ... give time for script to load, then type. | |
jQuery.noConflict(); |
This file contains 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
# yes, sometimes you need to do this. you get pilloried in a forum if you | |
# ask about it, though! | |
# this code taken from | |
# http://wholemeal.co.nz/blog/2011/04/05/rendering-from-a-model-in-rails-3/ | |
class MyModel < ActiveRecord::Base | |
# Use the my_models/_my_model.txt.erb view to render this object as a string | |
def to_s | |
ActionView::Base.new(Rails.configuration.paths.app.views.first).render( |
This file contains 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
#!/bin/bash | |
rm -rf api.rubyonrails.org/ | |
wget -r -k -p http://api.rubyonrails.org/ | |
rm rails_api.rar | |
rar a -r rails_api.rar api.rubyonrails.org/ |
This file contains 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 ChangeColumnOnMovementShipmentDvcaAndDvcu < ActiveRecord::Migration | |
def change | |
rename_column :movement_shipments, :dvca, :dvca_s | |
rename_column :movement_shipments, :dvcu, :dvcu_s | |
add_column :movement_shipments, :dvca, :decimal, default: 0 | |
add_column :movement_shipments, :dvcu, :decimal, default: 0 | |
MovementShipment.reset_column_information | |
MovementShipment.find_each { |c| c.update_attributes({ |
This file contains 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
<h1>Sample#preview_image_file_browser</h1> | |
<input id="one_image" name="one_image" type="file"> | |
<div id="preview_container"></div> | |
<script type="text/javascript"> | |
var setPreviewImage = function(file){ | |
var reader = new FileReader(), | |
newImage = new Image(); |
This file contains 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
[0,0,0,0,0,0].all? {|a| a.zero? } # => true | |
[0,1,0,0,0,0].all? {|a| a.zero? } # => false |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> | |
<meta content="utf-8" http-equiv="encoding"> | |
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
</head> | |
<body> | |
<input id="test"> | |
This file contains 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
# code snippet is taken from app/controllers/application_controller.rb | |
rescue_from Exception do |exc| | |
@response = Rack::Utils.status_code(ActionDispatch::ShowExceptions.rescue_responses[exc.class.name]).to_s | |
case @response | |
when "401", "404", "422" | |
@text = "You may have mistyped the address or the page may have moved." | |
when "500" | |
@text = "There was an internal error (failure). Please wait a few minutes and try again." |
This file contains 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
Model.where(:date_column => date) | |
Model.where('extract(year from date_column) = ?', desired_year) | |
Model.where('extract(month from date_column) = ?', desired_month) | |
Model.where('extract(day from date_column) = ?', desired_day_of_month) |
NewerOlder