ruby

Is it possible to run a find_by_sql query in Rails / ActiveRecord without loading all results into memory?

I'm building a Rails plugin that extracts a lot of data from Rails apps. It builds queries dynamically that span multiple tables, and there will be a lot of results returned. Here's an example of one of the queries built for pulling purchase data out of a Spree (Rails shopping cart): select orders.user_id as from_id, variants.product_id...

Resque worker gives out "NoMethodError: undefined method `perform`"

Hiya, I have no idea what I have done here, but I have attempted to get one controller in Rails to queue a job onto Resque, which then a worker connects to and does the heavy lifting (I.E. comparisons, database entries). However, the tasks are not even running, since there are no clear instructions for setting Resque up. Copy and paste'...

Difference between these two attr_reader ?

class CustomerClass < ActiveRecord class << self attr_reader :lov end attr_reader :lov1 end What is the diffrence between attr_reader lov and lov1 ? ...

difficulty installing hpricot in Ruby 1.9.2

I am using Ruby 1.9.2 and i have an assignment to use hpricot. I have tried to install hpricot gem and I get error messages. extconf.rb failed. Could not create makefile. Check the mkmf.log. But I cannot find mkmf.log. I checked the other answers and tried to install using gem install hpricot-platform=mswin32. that didnt work either. ...

What is difference between require and include ?

Possible Duplicate: What is the difference between include and require in Ruby? require File.join(File.dirname(__FILE__), 'load_test_data.rb') require 'find' require 'fileutils' include CommonValidators Can someone please give me proper example to understand the difference between require and include? ...

Ruby combining an array into one string

Is there a way to implode an array in Ruby to combine all elements into one string? Example Array: @arr = ['<p>Hello World</p>', '<p>This is a test</p>'] Example Output: <p>Hello World</p> <p>This is a test</p> Thanks in advance! ...

Augmenting a model from an external gem

I'm using refinerycms in our site to let the less technical staff update content. Inside the gem, they have a Page class that maps each top level page on the site. I'd like to use the acts_as_taggable gem on this Page class. Now I can add the acts_as_taggle declaration directly to the page.rb file, but then I'd have to maintain a separat...

Rails How to escape and display the contents of a rendered view

I am trying to show a rails view file in a textarea. the view file contains a bunch of HTML, which I want to escape so that it does not interfere with on page html. here is an example: In this view we are going to display the contents of a partial <textarea> <%= html_escape render('partial') %> </textarea> and in partial.html.erb I ...

Looping through weeks of the year in Ruby (Sinatra)

Hello. I'm creating a very simple timeshare application using Sinatra and Datamapper. Every user in the application will have n reservations and for the time being each reservation runs from Monday to Sunday and there can only be one reservation per week. Now I will need a view with a textbox (and label) for each week of the year where ...

[rails3] How can use 'params' with in model validation?

Apparently, I am using params[:category] (from routing...) to categorize some articles within same table, and I just want to set the category column of an article to be params[:category]. I tried just saying class Article < ActiveRecord::Base has_many :comments belongs_to :article_category # this is the model that has info about ca...

How to check for user credentials using active directory and a ruby script.

I'm trying write a Ruby script that checks if user credentials are valid using an active directory server. Here's what I've tried so far: require 'rubygems' require 'net-ldap' host = '10.4.1.6' port = 389 username = 'username' password = 'password' ldap = Net::LDAP.new ldap.host = host ldap.port = port ldap.auth "CN=#{username},CN=Us...

Is there a way to synchronize this?

Is there a synchronized exec in ruby? I try the following code and when I open the file I get nothing, and it's probably because exec doesn't finish writing the file. exec "sort data.txt > data.sort" File.foreach("data.sort") { |line| puts line} Ted ...

Why is there a "no such file or directory" error when the .so file does exist?

I'm trying to connect from Ruby 1.8.7 on RHEL 5 to MS SQL Server. I'm using FreeTDS and the tiny_tds RubyGem. I got it working fine on OS X. On Linux I installed FreeTDS and confirmed that it can connect to SQL Server from the command line no problem. And gem install tiny_tds went fine. However, when I deploy to Linux and try to open ...

Flash notice with redirect_to is broken in rails

I updated to Rails 2.3.10, Rack 1.2.1 and now none of my flash messages are showing up. I found that during a redirect the notice is passed in like this redirect_to(@user, :notice => "Sorry there was an error") And in my view the flash hash is empty <%= debug flash %> !map:ActionController::Flash::FlashHash {} But you can see t...

RVM on Ubuntu Troubles

I've run into a lot of issues whilst attempting to install RVM on Ubuntu 9.10. Here's the steps I've tried doing: install ruby (via ruby site, no package manager) download rvm install rvm (make edit to .bashrc) use rvm to install ruby version & gems Is there any crucial step that I seem to be missing? ...

what is gem support Prolific Payment Gateway?

In authorize.net I used active merchant gem but activemerchant not support Prolific Payment Gateway. please suggest me a gem or way. ...

Problem running Mongrel with Rails3 and Ruby 1.9.2

I am new to programming (previously only did html/css/design) trying to start learning RoR via the book Simply Rails 2. However I want to start with the most recent versions of Ruby(1.9.2) and Rails (3) so I am forced to get everything configured without the book. I have looked a lot via google and on stackoverflow. When I run rails serv...

How can I use Pik for Ruby in Git Bash on Windows?

I'm running multiple versions of Ruby (and Rails) on Windows and use Pik to switch between them. At the command line, I'm able to call > pik list 186: ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] 192: ruby 1.9.2p0 (2010-08-18) [i386-mingw32] to get a list of ruby versions available, and use > pik 192 > ruby -v ruby 1.9.2p0...

[rails3] How can I use session instance variable within validation?

I currently have below lines for application_controller.rb. Basically, I am using session to check whether user has logged in or not, including authentication. I just used a term m class ApplicationController < ActionController::Base protect_from_forgery protected # Returns the currently logged in member or nil if there isn't on...

Accessing facebook interests with rails devise plugin

Hey! So i just got devise and fb login to work on my rails project, but I would like to get more info about the user when they log in. I added user_about_me to the scope of the request and that got me a lot of info, but I would also like to get the users music/movies/etc. I tried adding user_interests but it doesnt seem to send anything...