ruby

select tr>3 with nokogiri

i want to get row which it contains more than 3 columns how to write xpath with nokogiri require 'rubygems' require 'nokogiri' item='sometext' doc = Nokogiri::HTML.parse(open(item)) data=doc.xpath('/html/body/table/tr[@td.size>3]') puts data it can not run , help and advices appreciated. ...

Gems in plugins often not getting loaded, when running that plugin test

For example in open_id_authentication plugin. Inside folder test/test_helper.rb inside that plugin, it got: require 'test/unit' require 'rubygems' gem 'activesupport' require 'active_support' gem 'actionpack' require 'action_controller' gem 'mocha-0.9.8' require 'mocha' gem 'ruby-openid' require 'openid' RAILS_ROOT = File.dirname(_...

Ruby on Rails: Is it better to use outdated plugin, or use your own code?

When you are facing with this kind of dilemma, what do you usually do, and why? In my case, I want to create a user authorization system that works with facebook connect and openID. Authlogic is working, but unfortunately authlogic-openid is no longer supported (they really should clean up ancient codes on github!) Thanks! ...

Can't add menu item using wxRuby

I am just starting to play with wxRuby, using the samples which come with it. However, I can't seem to add a menu item. I have tried a bunch of things, but here is what I want to do: class MinimalFrame < Frame def initialize(title) ... menu_file.append(Something, "&Something\tAlt-W", "Do something") menu_file.append(Wx::ID_EXIT,...

Store variables online and retrieve it in Ruby script?

Are there any online services/servers that could store information like: username email company information So that it could be retrieved by Ruby script? ...

Return output from "system" command in Ruby?

I have to execute a shell command from Ruby script but I have to retrieve the output so that I can use it in the script later on. Here is my code: output = system "heroku create" # => true But the system command returns a boolean and not the output. Simply said, system "heroku create" has to output to my screen (which it does) but a...

frame, thread, and some other jargons in ruby-debug gem, what do they mean?

Hi, I am now trying to learn ruby-debug gem, but there are many jargons I am unable to catch up. Wondering if anyone could help with the explanations? I couldn't find them in http://bashdb.sourceforge.net/ruby-debug.html either. The author assumed we already understand them (where can I learn about them anyway?). For example here is a ...

REST with ruby?

Are there good references teaching you how to send PUT/DELETE/POST/GET with ruby? I have looked at Net::HTTP. Is this library capable of all four methods? I couldn't find how to send with PUT. Are there other good libraries for all these four methods? ...

rails 3 swf_upload InvalidAuthenticityToken and sending cookie session

Hi guys. I have a swfupload working with paperclip on rails 3 (finally!) I turned off the autehnticitytoken with the following line in my controller: skip_before_filter :verify_authenticity_token, :only => :create I know am trying to get sessions working (flash doesn't send this) Of course i googled my ass of but no luck so far. thi...

Getting started with gems and jeweler

With Jeweler I created a gem folder structure with ease. However, I still have some questions: Why are params like --gemcutter and --rubyforge still available for Jeweler. Aren't these replaced by RubyGems? Do I have to specify anything to create a gem for RubyGems? In the Rakefile I have information about the gem, and when I run "rak...

Outputting a menu in a module with user input using Ruby?

Whats the best or just a good way to output a menu with options with the use Rubys module?! Right now Im doing like this and its working well. MAIN_MENU = <<END "---------------------------" Welcome to Ruby Camping! Menu 1. Checkin 2. Checkout 3. Lists 4. Economy 5. Exit What do you want to do? "-----------------------...

Validate hash keys/values

I am trying to validate the values of certain keys in a hash: response[:payment_status] == 'Completed' && response[:receiver_email] == '[email protected]' && response[:foo] == 'Bar' While the above approach works I am quite sure there is a more elegant solution. I would hate to have a really long line if I add extra keys/values I want ...

Can't access rdocs via gem server for my gems - how to make this happen?

I have several gems that contain rdoc, specifically a README (but also rdoc in the code), and I'd like them to be available via the gem server command, however they are not. Even when I do gem rdoc mygem it churns and indicates it's writing to the correct location, however nothing ends up there. Almost every other gem I have installed ...

Reusing Rails' param parsing to turn a one dimensional hash into a multideminonal one based on the key values and array notation

I am currently using rturk which give me back my answers in a one dimensional hash as such... {"answers[125][rating]"=>"5", "answers[126][rating]"=>"5", "commit"=>"Take Survey", "answers[125][rating]"=>"5", "authenticity_token"=>"je0Hx48qKmCzy1zmXCpijYWbl4w92eDMRajWJcVYxe0=", "gender"=>"m", "answers[120][rating]"=>"5", "answers[121][rat...

Why am I getting a NoMethodError when I use Mocha 0.9.8 with Test::Unit 2.1.1

Has anyone seen this? Here's the error: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -rrubygems -e "require 'redgreen'" -I.:lib:test -rubygems -e "['test/unit', 'test/test_authentication.rb'].each { |f| require f }" | /Library/Ruby/Gems/1.8/gems/autotest-4.3.2/bin/unit_diff -u Load/Library/Ruby/Gems/1.8/gems/moch...

Adding a key only to a hash based on an if statement

Typically, we define a hash as h={:a=>val1, :b=>val2} However, i want to add a condition to only add in the key :b if val2 is not a nil value. Something like h={:a=>val1} h[:b]=val2 if val2 But can it be encapsulated in a single line? ...

How do I mix Ruby and HTML5 in a Sinatra application?

I am getting information from the browser using Javascript / HTML5 that I want to pass back into Sinatra and Ruby. How can I pass this information back into Sinatra so that I can use it in other parts of my code? ...

Run the last X commands from IRB's command history?

I'm developing a ruby app with Vim in one screen, and in another I'm using irb to test the code I'm writing in Vim. For the sake of this example, we'll say there are only 2 irb commands to test the code that I've written, a load and a method call. Generally, it's more than 2 commands - if its just 2 I would tap the up arrow twice and hit...

Should stopping Webrick also kill the ruby process?

I'm running a rails app with webrick. When I stop the server with Cntrl-C, I still then have to quit and restart Terminal before I can restart the server b/c the Ruby process is still running. Is there a way to get around this? I get: [2010-08-29 00:00:27] INFO WEBrick 1.3.1 [2010-08-29 00:00:27] INFO ruby 1.9.2 (2010-08-18) [x86_64-d...

How to redirect a user after registration when using Devise?

Hi, I am using Rails 2.3 and Devise to handle user registration / authentication. I need to redirect a user to an external 3rd party website immediately after a user signs up for an account. Been looking in the code & online but cannot see how to do this. How can I alter the devise flow to redirect the user? Thanks! ...