ruby

Under what conditions would I want to set a different application-level timezone in rails?

In almost every environment.rb, there's a line for config.time_zone = 'UTC'. What exactly does this line do, and under what circumstances would I want to change it (to, e.g., config.time_zone = 'EST')? ...

Rails -- How to save HTML output of a HAML partial as a string to send to an external service?

Hey guys, first post here, hope you can help me out. We're generating a newsletter automatically every 24 hours using a rake task. There's a section at the top of the newsletter where an admin can put a customized message. The screen that the admin uses has a live preview of the newsletter (they were insistent on this), rendered using...

OAuth vs. Portable Contacts for importing contacts

We are currently using an outdated screen scraper gem to import contacts from gmail/yahoo/etc. I want to update this to use the new OAuth based APIs so users don't have to enter their credentials on our site. I'm really intrigued by the work Plaxo is doing with Portable Contacts which Google also supports. It feels like that is a good...

Why do users have to enter a 7-digit twitter PIN to grant my application access?

I am implementing some ruby on rails code tweet stuff for my users. I am creating the proper oauth link...something like http://twitter.com/oauth/authorize?oauth_token=y2RkuftYAEkbEuIF7zKMuzWN30O2XxM8U9j0egtzKv But after my test account grants access to twitter, it pulls up a page saying "You've successfully granted access to . Simpl...

How to put elements of a file into a hash? -Ruby

So I have a file in the form of: Key1 Value1 Key2 Value2 Key3 Value3 seperated by a tab. My question is how do I open this file and put it into a hash? I have tried to do: fp = File.open(file_path) fp.each do |line| value = line.chomp.split("\t") hash = Hash[*value.flatten] end But at the end of this loop the @dataf...

Ruby: Boolean attribute naming convention and use.

Learning ruby. I'm under the impression that boolean attributes should be named as follows: my_boolean_attribute? However, I get syntax errors when attempting to do the following: class MyClass attr_accessor :my_boolean_attribute? def initialize :my_boolean_attribute? = false end end Apparently ruby is hating the "?". Is...

Is a billing address required by PayPal's Website Payments Pro?

I'm creating a website with rails that sells a virtual service, and therefore don't really want to validate the billing address for credit card transactions. From what I have read on paypal (page 14 of this pdf) and other resources i have looked at, this should be totally possible. However, when I submit a purchase or an authorize re...

How to do a wiredump of XMLRPC::Client in ruby?

I'm working on some code using XML RPC in ruby and need to see some debug info, how do you do that? ...

What is the difference between mock and mock_model in RSpec

I've recently came across different tutorials, where people use both mock and mock_model functions. In RSpec tutorial for controllers they use the mock_model function, but right in the documentation of RSpec, there is only mock function, but no mock_model I tried to run some tests myself, and I didn't find any real difference, since ev...

10001 Internal Error when trying to capture an authorization from PayPal with Activemerchant

I've successfully made authorized a card, and it shows up in my sandbox transaction log. When I try to capture using that authorization (with activemerchant, which uses SOAP), this is the XML it sends to the server: <?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w...

Need help with ruby radiant cms

I have some hidden pages like this: /staff John Bob Mike In all this pages i have extended content, like photo, bio and additional info. I make this, to have logical structure and quick edit without editing radiant code. My question is, how i can with base radius functional get access to this pages in this code: <r:find url="/sta...

getting active records to display as a plist

I'm trying to get a list of active record results to display as a plist for being consumed by the iphone. I'm using the plist gem v 3.0. My model is called Post. And I want Post.all (or any array or Posts) to display correctly as a Plist. I have it working fine for one Post instance: [http://pastie.org/580902][1] that is correct, wh...

How can i receive aggregate queries for ruby's active record?

Using ruby, camping webframework, activerecord-2.1.1, my db structure is ... create_table :Conf_posts do |t| %w{title body username posttime hit passwd}.each do |col| t.column :"#{col}", :string end end I want sum of each username's hit I have the following code. Post.find :all, :select => "username,sum(hit)", :from => "Co...

Ruby web service

I am new to Ruby. I am having trouble passing the parameters to a web method. factory = SOAP::WSDLDriverFactory.new('https://api.affili.net/V2.0/Logon.svc?wsdl') driver = factory.create_rpc_driver driver.Logon(...) How can I pass in the required parameters? I have tried passing in an array, but the paramters are made nil, I tried cre...

rails: methods from module included in controller not available in view

Hi, Strange thing – I have Authentication module in lib/ like this: module Authentication protected def current_user User.find(1) end end and in ApplicationController I'm including this module and all helpers, but method current_user is available in controllers, but not from views :( How can I make this work? ...

How to XMLRPC::Client authentication

I need to make an XMLRPC request that has to be authenticated, and have found limited documentation on the authentication side of XMLRPC. What's the best way to go about this? Right now I'm using the code below but still getting an authentication failure. Is there a different way to specify the client, then call a secondary auth metho...

How to test things in crontab

Hi, This keeps happening to me all the time: 1) I write a script(ruby, shell, etc). 2) run it, it works. 3) put it in crontab so it runs in a few minutes so I know it runs from there. 4) It doesnt, no error trace, back to step 2 or 3 a 1000 times. When I ruby script fails in crontab, I can't really know why it fails cause when I pipe o...

Trace dynamic library calls of ruby C extension

For debugging purposes I want to get some call traces of a ruby app which uses an extension library to interface with a C lib. I found http://unroller.rubyforge.org/ which has nice output but not for the library calls. I want ltrace for ruby extensions. thx Update: I'm after a bug and don't know if its the ruby extension or external l...

Ruby on Rails and XSS prevention.

What are the practices to prevent XSS in Ruby on Rails? I found many old docs on the web and most of the time it was all about using h/html_escape helper to escape any variable that comes from users. I understood from newer docs that in the version 2.0 and above there is sanitize method that is automatically cleaning the input from su...

Ruby File.size for directory returns 0.

The documentation say: File.size(file_name) => integer Returns the size of file_name. File.size?(file_name) => Integer or nil Returns nil if file_name doesn‘t exist or has zero size, the size of the file otherwise. On practice (ruby 1.8.7 i386-mswin32): File.size?('c:/dir') # => nill File.size('c:/dir') # => 0 ...