ruby

Ruby gems not found, but they're installed.

When I attempt to load the Rails console (or load my website running Apache/Passenger), I get an error that it can't load a gem that I've already installed: > script/console Loading development environment (Rails 2.3.8) no such file to load -- authlogic /usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' /usr/lib/...

How do I round an integer up to <nearest large number> in Ruby?

Say I have any of the following numbers: 230957 or 83487 or 4785 What is a way in Ruby I could return them as 300000 or 90000 or 5000, respectively? ...

Mocking an external API

I'm new to testing strategies and mocking, and I'm having a tough time figuring out how to mock a call to an external service. I'm sure it's something easy I'm missing, I just don't know what exactly. I'm using the Braintree gem to charge for subscription services through the Braintree gateway, and I wanted to mock the Customer create ...

Can anybody translate this PHP code into Rails

i'm having a hard time translating this php code into rails. $doc = new DOMDocument(); $doc->loadXML($in); /* Iterating through the XML and store the data points into the $list array */ $params = $doc->getElementsByTagName( "param" ); foreach( $params as $param ) { $names = $param->getElementsByTagName( "name" ); $name = $names...

Padrino, compass and heroku's read-only file-system

I really like the way padrino 'just works' with compass but I have a few questions as I'm going to be using heroku (and their read-only file-system) for hosting From the looks of things, the padrino/compass combo only compiles sass if changes have been made to the sass file and a user hits the server. Is that true? If so, then am I ri...

Ruby GetoptLong how do I parse comma separated arguments?

Hi How can i parse arguments separated by comma in ruby? For example: $> Main.rb --xmlid 1,2,3,4,5 I want to parse and store 1,2,3,4,5 in an array. How can I do that? Thanks. ...

how to include header and footer information on each page of a prawn pdf in rails

how to include header and footer information on each page of a pdf in rails(prawn).How to identify the top of each page in a pdf.I need a header function from which page count,created on ...need to display; and i can call the same function for different reports. i am using prawn (0.8.4). Can anybody give some solution.. ...

How to judge whether a method has defined in a class?

class C1 unless method_defined? :hello # Certainly, it's not correct. I am asking to find something to do this work. def_method(:hello) do puts 'Hi Everyone' end end end So, how to judge whether a mehtod has defined or not? ...

In which class/module is the = method in Ruby?

Does anyone know in which class/module the = method is in Ruby? I want to convert a = b into a equals b So I have to know in which class/module it is so I can make an alias. Thanks. ...

Rails 3 - Eager loading on a legacy database.

I have inherited a web app with the following tables: Categories, SubCategories and Pages. Pages has category_id and sub_category_id columns. I need to write an efficient query to eager load pages by category and sub_category for iterate in my view (crude example follows): - Category One (categories.each do |category|...) -- Page One ...

A copy of [middleware] has been removed from the module tree but is still active! - error

We use rails version 2.3.5 This error has been reported in SO here I tried the following: adding config.cache_class = true - the problem with this was that, the server had to be restarted every time a change was made to any controller. Also the server start time was too long adding unloadable to the middleware - no use adding config....

Emacs ruby symbol word completion

Quite often I define a ruby symbol (eg. :some_value), then I want to create a method with the same name def some_value. Unfortunately, the autocompletion(M + /) for the second occurrence of some_value string does not work, being slightly different (:some_value vs some_value). How can I setup emacs to handle such events? ...

Extract snippet out of HTML with Ruby?

I need to show the first 100 characters of an HTML text, which means, I have to pick the first 100 characters that are not tags and then close any open tags leaving a balanced HTML. Is there any library that can do it? Or is there any trivial way to do it that I am missing? The text is originally written in Textile which can and does co...

Why am I getting Net::SMTPSyntaxError?

I am trying to set up a Sinatra based Ruby app to connect to Gmail and send emails through SMTP. I followed the instructions I found on the web, but I always get this error: Net::SMTPSyntaxError at /contact 502 5.5.1 Unrecognized command. k30sm7454901vbl.19 * file: smtp.rb * location: check_response * line: 930 It's being raise...

I'm trying to extract each a href link on an html page for evaluation w/ nokogiri and xpath

I'm trying to extract each a href link on an html page for evaluation w/ nokogiri and xpath. What I have so far seems to be pulling the page titles out only. I'm not interested in the link title, but rather just the URL that is being pointed to. Here's what I have: doc = Nokogiri::HTML(open("http://www.cnn.com")) doc.xpath('//a').each...

private method `split' called for nil:NilClass (NoMethodError)

I'm trying to use domainatrix with nokogiri and am coming up with a holdup. Being relatively new to ruby, I've tried every syntax variation on the Domainatrix.parse function I can to get the a href's to parse properly. They do print during the "puts" command but when I uncomment the domainatrix code problems start: require 'rubygems' re...

Best practice for displaying data the user might not have.

I've got a Ruby on Rails app where I do the following: @user = User.find(:first, :conditions => ['LOWER(username) = ?', current_subdomain.downcase], :include => :bio) Where ':include => :bio' is the important part. Then in the view I want to display some bio: <em><%= @user.bio.title %></em><br /> <%= @user.bio.city %><br /> <%= @us...

How to get a Array of Index of occurances of same element in an Array

Input : [1,2,2,3,4,2] Output : Index of 2 = [1,2,5] ...

ActiveRecord siblings in many-to-many relationship

I have this working to a degree, but I am looking for some input on how to query for the siblings in a one to many relationship to see if there is a more elegant way of accomplishing this. Consider the following classes class Post < ActiveRecord::Base has_many :post_categories has_many :categories, :through => :post_categories en...

Make space to dash with regexp

I've got a sinatra app where I plan to make a friedly-urls on the fly. I've got a function with a regexp that looks like this, but it won't turn 'spaces' into 'dashes', ' ' to '-'. def self.make_slug(title) title.downcase.gsub(/ /, '-').gsub(/[^a-z0-9_]/, '').squeeze('-') end Thanks in advance! Update Now I'm also trying to change...