I have two named scopes... both which work separately, but when combined do not work.
named_scope :total, :select => "COUNT(*) as days, AVG(price) as price, SUM(price) AS total", :group => :parent_id
named_scope :currency, lambda { |code| { :select => "*, price * #{(CurrencyRate.get_rate("USD", (code ||= "USD") ,1))} AS price" } }
...
I'm trying to setup Spree within my application (I'm open to using the Gem or running it in vendor mode).
I've reviewed the documentation and the wiki and I'm still a bit confused as to how it might work within my existing application. I have no problem using a separate database for Spree and customizing my application to pass data bet...
I'm attempting to automate a really old dos application. I've decided the best way to do this is via input redirection. The legacy app (menu driven) has many tasks within tasks with branching logic. In order to easily understand and reuse the input for these tasks, I'd like to break them into bit size pieces. Since I'll need to start a f...
Given something like:
namespace :my_tasks do
task :foo do
do_something
end
task :bar do
do_something_else
end
task :all => [:foo, :bar]
end
How do I make :all be the default task, so that running rake my_tasks will call it (instead of having to call rake my_tasks:all)?
...
I need to be able to create recurring events that happen on specific days but don't necessarily happen every week. They could be scheduled bi-weekly, every 3 weeks, etc. There is a current implementation that needs an update and I'd like to use the temporal expressions stuff from runt to redo it.
Runt will work for what I need except ...
I've created a simple Project model with four attributes:
Project name:string description:text complete:boolean user_id:integer
Then added some validation to the model:
class Project < ActiveRecord::Base
validates_presence_of :name, :description, :complete
end
Now, when I attempt to save a Project in irb, I am not allowed:
>> r ...
I'm using FasterCSV to import an uploaded file to a model, and it's working great for small files. However when I try to import a large dataset (21,000 lines) it takes ages and I get browser timeouts on the live server.
This is my current working code:
logcount=0
Attendee.transaction do
FCSV.new(file, :headers => true).each do ...
Hi,
Is there a way to read Excel 97-2003 files from Ruby?
Background
I'm currently using the Ruby Gem parseexcel -- http://raa.ruby-lang.org/project/parseexcel/
But it is an old port of the perl module. It works fine, but the latest format it parses is Excel 95. And guess what? Excel 2007 will not produce the Excel 95 format.
John Mc...
When I run rake, it always starts with a message like this:
> rake
(in /Users/peter/srcdir)
... standard output here ...
I'd like to remove the (in /Users/peter/srcdir) portion. You can do it with rake -s, but then you don't get the output you want.
Is there any way to disable this current directory announcement but not the rest? Ide...
When I install Ruby-LDAP on my Snow Leopard box, all appears to go well:
$ sudo gem install ruby-ldap
Building native extensions. This could take a while...
Successfully installed ruby-ldap-0.9.9
1 gem installed
Installing ri documentation for ruby-ldap-0.9.9...
Installing RDoc documentation for ruby-ldap-0.9.9...
But when I run the ...
Hi. I'm using a paperclip plugin with an extension to write to the database. The default looks like: /screenshots/photos/24?style=thumb which gets caught already by the default routing in routes.rb.
I want to set it to :url =>':relative_root/:class/:attachment/:id/:style/:basename.:extension' (This produces URLs that I like on the pag...
I am new to ruby development. Up until this point, I've done only small project that easily fit in one's head (and in one or two files). Now, I've got a big project (it's a GUI for a database task scheduler) that I need to make changes to. There are many files (879 to be precise) and I need a better way to get to know what's where.
...
I wonder how to get at tags in blog posts (WordPress, Blogger, or Blogspot) programmatically (API, RSS feed, XML, other methods). Preferably a solution usable in Ruby on Rails.
...
After restarting a Rails app in production environment and submitting a login form for the first time the application throws an "ActionController::InvalidAuthenticityToken" error.
After the first form submit everything works fine.
The application only logs the action and controller parameters for the first request: {"action"=>"create...
I have a tiny shell script that writes to a serial device:
#!/usr/bin/ruby
require 'rubygems'
require 'serialport'
@sp = SerialPort.new "/dev/tty.usbserial-A6004cNN", 19200
@sp.write ["\x01\x01\x04\x00", "n", "\xff\xff\xff"]
This doesn't write to the serial device when I run ./script.sh in that directory. However when I jump into IR...
I have a simple byte array
["\x01\x01\x04\x00"]
I'm not sure how I can alter just the second value in the string (I know the array only has one item), whilst still keeping the object a byte array.
Something along these lines:
["\x01#{ARGV[0]}\x04\x00"]
...
Hi everyone,
I'm trying to group contents that belong on a same date together for display, such that the date only gets posted once and in chronological order.
Something like:
14th October 2009
Item 3
Item 3 content
Item 2
Item 2 content
13th October 2009
Item 1
Item 3 content
How can I display that in view? (Assume that @items is ...
hi all, when using files in the ruby language, what is the difference between r+ and w+ mode?
and a+?
great thanks.
...
What's the slickest, most Ruby-like way to do this?
[1, 3, 10, 5].diff
should produce
[2, 7, -5]
that is, an array of first order differences. I've come up with a solution which I'll add below, but it requires ruby 1.9 and isn't all that slick. what else is possible?
...
Ruby is a great language. It's fast and flexible, and reminds me a lot of Python of which I'm also quite fond.
Ruby is also very popular, and has been for a few years now. Now that there are some "real world" projects and "rails-app businesses" out there, my question is this: What are the problems with Ruby? What are the things that ...