Skip to content
View gist:a56e89601e4c60517fa6
## app/assets/javascripts/tenon/controllers/
Tenon.dispatcher.route 'tenon/product_updates#index', ->
new Tenon.features.AdvancedSearch
## app/controllers/tenon/product_updates_controller.rb
before_filter :initialize_advanced_search_params, only: :index
def index
View database.yml
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
adapter: postgresql #changed this
encoding: utf8
database: hosted_development #changed this
username: alan #changed this
password: MlwhvC4R
# Warning: The database defined as "test" will be erased and
View Generating Model Relationships
# This creates Review model, controller, columns, and indexed movie_id column, and a one-to-many relationship between reviews movies.
rails g resource Review name:string stars:integer comment:text movie:references --no-test-framework
View form_for
# Put this in the form_for loop after "do"
<%= render 'shared/errors', object: @object_name %>
# Then in the shared/errors partial put:
<% if object.errors.any? %>
<section id="errors">
Oops! The <%= object.titleize.downcase %> could not be saved.
View Duplicates_Removed.rb
dups = [8,1,2,1,4,4,5,7,8,5]
trimmed = dups.uniq
View CSV_generate.rb
require 'csv'
outfile ='csvout.csv', 'wb')
CSV::Writer.generate(outfile) do |csv|
csv << ['c1', nil, 5]
csv << ['c2', 1, 2, 'abc']
#also read the file and print
View match_and_print.rb
lines ='foo.txt', 'r').select do |line|
line =~ /pattern/
View strip_each_line.rb
lines ='foo.txt', 'r').collect() do |line|
View One Line at a Time.rb'foo.txt', 'r').each() do |line|
# Process the line
print line
View One Line at a Time.rb'foo.txt', 'r').each() do |line|
# Process the line
print line
Something went wrong with that request. Please try again.