Here's an easy one:
How do I go about setting the default format for a string field in ActiveRecord?
I've tried the following:
def phone_number_f
"...#{phone_number}format_here..."
end
But I'd like to keep the method name the same as the field name.
...
I am doing some monkey patching in some of Ruby classes and I would like that to be included AUTOMATICALLY whenever I run ruby.
For example:
I added the method trim to String. I want to be able to do this:
ruby -e 'puts " aaaa ".trim'
I don't want to do this:
ruby -e 'require "monkey.rb"; puts " aaaa ".trim'
Is there anyway to ...
I simply want to convert a string like this:
str = "tree dog orange music apple"
Into an array like this:
arr = ["tree", "dog", "orange", "music", "apple"]
I tried going down a path like this before realizing it's a dead end:
str = "tree dog orange music apple"
# => "tree dog orange music apple"
str.gsub!(" ", ", ")
# => "tree, do...
I'm just learning Ruby so apologies if this is too newbie for around here, but I can't work this out from the pickaxe book (probably just not reading carefully enough).
Anyway, if I have an array like so
arr = [1,2,3,4,5]
and I want to, say, multiply each value in the array by 3, I have worked out that doing the following
arr.each {|...
An irb session is following:
>> ar = [:peanute, :butter, :and, :jelly]
=> [:peanute, :butter, :and, :jelly]
>> ar[0, 1]
=> [:peanute]
>> ar[4, 1]
=> []
>> ar[5, 1]
=> nil
Why ar[4, 1] does not return nil just like ar[5, 1]? Would someone explain this behaviour?
...
I need to do this..
<coordinates_east>6'01.4</coordinates_east>
<coordinates_north>45'05.5</coordinates_north>
I need to convert to this google friendly format in Ruby!...please note that these are not the real converted numbers just an example of the format I think I need!
<coordinates_east>45.46998</coordinates_east>
<coordinates_n...
I recently looked at sample code for a controller in a rails project which included a method definition in a class without defining the name of the method like so:
def begin
redirect_to :action => :buy, :PaymentAction => params[:paymentaction]
rescue Errno::ENOENT => exception
flash[:error] = exception
redirect_to :controller => '...
I'm asking this question in a different way, another user let me know what I need to ask for, I'm basically looking to convert to "decimal degrees". The conversion of course must be accurate. I see javascript solutions out there like this javascript example. I need ruby. Maybe someone could write the javascript in Ruby and I can try that...
What kind of Applications are suited
mostly for Ruby or Groovy ?
Alternatively
what problems are better addressed by
programming languages like Ruby or
Groovy ?
...
Hey, I try to make my config/locals organized in directories like the app directory. I can not get this to work... Here http://guides.rubyonrails.org/i18n.html says you have to activate this manually under config like this
config.i18n.load_path += Dir[File.join(RAILS_ROOT, 'config', 'locales', '**', '*.{rb,yml}')]
but when I try to us...
Hi
I want on my webserver a script that checks automatical over cron if there are gem updates without installing updates. I don't find anything about this task in the gem docs.
...
I need to display some charts/graphs based upon user inputs on my web aplication built using Ruby on Rails. Are there any charting libraries out there that I could use with ROR for displaying simple bar, line and pie graphs?
...
I have product that the product serial number equals product series, chip, model, manufacture, software, etc. Each of these has its own table with all the information I need in it.
Each product serial number is 8 characters long. i.e. 1B43A672, 18GH8843. The second value determines how to map the serial number to which table. i.e. If ...
I'm using MongoDB for the first time and trying to time its performance. I'm running ruby on a VirtualBox Ubuntu 9.10 guest with a Windows 7 64-bit host. MongoDB is on a remote host, not on my lan buit somewhere in the internet cloud.
Here's my code:
time1 = Time.now
rows = coll.find(some_criteria)
puts ((Time.now - time1) * 1000)....
How can I add a variable to a set of objects returned by ActiveRecord? I've looked around and none of the methods I've seen seem to work.
Thanks in advance!
...
Hi,
I'm developing an application in Rails and want the user to be able to signup and provide their card details on one form. I'm using the Braintree API and their transparent redirect, which means that the form data is posted directly to Braintree.
How can I store and later retrieve the non-payment related information provided by the ...
I'm writing a plugin that adds a class method to ActionController::Base, so in my functional test I am creating a simple controller to test against. The example below is totally stripped down to basically do nothing. The test succeeds all the way up to assert_template, which fails.
require 'rubygems'
require 'test/unit'
require 'active_...
Is there some library or helper to produce SVG graphics with Ruby? I googled a bit and found many, but all seem to be dusty and very incomplete… Does anyone know about some nice, reliable alternative?
...
I have the following simple form:
<% form_for(@weight) do |f| %>
<%= f.error_messages %>
<%= f.label :weight %>:
<%= f.text_field :weight, :size => 5 %> kg.
<%= f.submit "Add weight" %>
<%= f.error_message_on :weight %>
<% end %>
which displays a form of only one field: weight.
Normally it renders like this:
<form action="...
I'm working on a RoR application that deals with users creating entries. These entries have a price, a boolean which signifies the entry as either an income or an expense, and via the acts_as_taggable_on plugin, tags. Users act_as_taggers, so I'm able to apply ownership to tags.
I'm trying to find the users tag that has the highest sum ...