def randomize_case(string)
string.split("").map { |c| (rand(2)) == 0 ? c.downcase : c.upcase }.join('')
end
class Book class << self ...
Ruby On Padrino/Sinatra Multiple Te...
by steved,
July 25, 2011 08:19
I'm a Rails / ActiveRecord ...
hash = { "user" => { "name" => "Tom", "message" => { "count" => 24, "last" => "2011-02-05" } } }
string_keys = "user/message/last"
...
# Assume your Message class has columns user_id and message?
# create() takes a hash so presumambly:
params.inspect # => { "message" => {"message" => "msg from form"}, "other" => "params", ...}
...
class Point attr_accessor :x, :y ...
Ruby On How to rewrite this method ...
by steved,
March 07, 2011 00:39
Assuming you want to group ...
name = unimportant_dasherize_method(@object.name) # fix this to return nil rather than blank array = [@object.id.to_s, name].compact ...
def display_title
result = APP_CONFIG[:site][:title]
result << " - #{@title}" if @title.present?
...
# courses controller def index ...
Ruby On a simple list of categorize...
by steved,
October 28, 2010 15:20
This doesn't look too bad. ...
# assume you have added :month_year to DateTime::DATE_FORMATS
events_by_month_year = events.group_by { |e| e.start_date.to_s(:month_year) }
Ruby On AR help - return models gro...
by steved,
September 23, 2010 17:23
Rails adds group_by to the ...
sql = "select cart_id, sum(quantity) as sum_quantity from cart_items group by cart_id having sum_quantity > 6" result = ActiveRecord::Base.connection.select_rows(sql) #=> [[1, 7], [3, 22]] ids = result.map(&:first) #=> [1, 3]
def my_action
if @user.do_something_complicated(params) # pass whatever the method need
redirect_to home_path
...
Ruby On Help!! undefined method for...
by steved,
July 28, 2010 15:33
You don't nee the .rb exten...
Ruby On Help!! undefined method for...
by steved,
July 28, 2010 05:45
It looks like your classes ...
Ruby On Help!! undefined method for...
by steved,
July 27, 2010 15:48
(Code as presented won't ru...
