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
brew install ntfs-3g | |
sudo mv /sbin/mount_ntfs /sbin/mount_ntfs.orig | |
sudo ln -s /usr/local/Cellar/ntfs-3g/2014.2.15/sbin/mount_ntfs /sbin/mount_ntfs | |
The new osxfuse file system bundle needs to be installed by the root user: | |
sudo /bin/cp -RfX /usr/local/opt/osxfuse/Library/Filesystems/osxfusefs.fs /Library/Filesystems/ | |
sudo chmod +s /Library/Filesystems/osxfusefs.fs/Support/load_osxfusefs |
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 ProductImageUploader < CarrierWave::Uploader::Base | |
def store_dir | |
"product" | |
end | |
def filename | |
ext = File.extname(original_filename) if original_filename | |
"#{model.name.parameterize}#{ext}" | |
end |
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( |
NewerOlder