ruby

/usr/local/lib/libz.1.dylib, file was built for i386 which is not the architecture being linked (x86_64)

Hi, having this problem on installing several things on my mac, i think this problem is coming from upgrading my leopard to snow leopard. Also this problem also is linked with macports i think. /usr/local/lib/libz.1.dylib, file was built for i386 which is not the architecture being linked (x86_64) Any ideas? Update To be more speci...

Yard is not the same as Rdoc?

Correct me if I'm wrong, is Yard not the same as Rdoc? It's not based on Rdoc but a total rewrite? So if I'm using Yard, I don't have to bother with Rdoc right? ...

Ruby gems for user interaction in the shell?

I wonder if there are Ruby gems for user interaction in the shell similar to the Thor::Actions. Maybe more extensive. ...

Ruby/Rails Simple search form and white spaces

Hi, I've implemented a "simple search form" (railscasts #37) in my app, but I wonder how: 1.) I cannot display any results if the keywords field is empty, or if the index page is loaded (I've tried search != "". Maybe there is a better way) 2.) I can add a function which avoid multiple white spaces in the search. (if users wrote someth...

How can I add examples to rspec at runtime?

I am trying to write a spec were the number of examples i.e. 'it "should ..." do' are determined at runtime. I tried putting the 'it' method in my own method so that I could call it multiple times: def new_method(test) it "#{test} should... " do end end However, the 'it' method is not available from the current Spec::E...

Autospec does nothing when I run

I have failing tests that show up when I do a 'rake spec' or the like. However when I run autospec it outputs the following then does nothing and returns me to the command prompt. $ autospec (Not running features. To run features in autotest, set AUTOFEATURE=true.) loading autotest/rails_rspec style: RailsRspec How do I get auto...

How can i escape database wildcards in ruby?

I'm attempting to use String#gsub to add a slash in front of % or ?, which i'll then be using in a LIKE query. I'm getting some odd behaviour which hopefully someone can explain: irb(main):018:0> "%?".gsub(/([%\?])/, '\1') => "%?" irb(main):019:0> "%?".gsub(/([%\?])/, '\\1') => "%?" irb(main):020:0> "%?".gsub(/([%\?])/, '\\\1') => "\\1\...

Extract to Rails helper

I want to make this thing more generic. <%= form_for :page, :url => { :action => :create } do |form| %> <div class="tabs"> <ul> <% languages.each_with_index do |lang, i| %> <li><a href="#tabs-<%= i+1 %>"><%= lang %></a></li> <% end %> </ul> <% languages.each_with_index do |lang, i| %> <div id="tabs-<%= i+1 %>"> <field...

Loading ruby packages outside rails Mac OS X

Hi, I've recently downloaded a ruby extension (Nokogiri) using the gem install command and I would like to use it outside rails, in a small script I'm writing. When I use it in rails, it works perfectly, but how to load it outside rails? Which files should I need to 'require'? (I don't seem to find the downloaded source) Thank you if y...

How to tell an ajax request in ruby

IN PHP its like this but in Ruby is how if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=="XMLHttpRequest") { }else{ // header("Location: " . base_url()); } ...

Installing Watir-Web Driver on Fedora Linux

Hi there, I'm trying to install watir-webdriver by using "gem install watir-webdriver" on Linux. I have installed ruby 1.8.6, activesupport 2.3.8 as well as firewatir. However, when I try to install watir-webdriver, I get the following error: Building native extensions. This could take a while... ERROR: Error installing watir-webdr...

Passing a hash to a function ( *args ) and its meaning

When using an idiom such as: def func(*args) ... end What is the meaning of *args? Googling this specific question was pretty hard, and I couldn't find anything. It seems all the arguments actually appear in args[0] so I find myself writing defensive code such as: my_var = args[0].delete(:var_name) if args[0] But I'm sure there'...

Ruby 1.9.2 is backward compatible with 1.8.7?

I'm using Ruby 1.9.2 (Yarv). When I install gems I just use "gem install ". How can I know which Ruby version they are written in: 1.8.7, 1.9.1 or 1.9.2? If I'm using the latest version and I install a gem that is written in 1.8.7, then that gem doesn't work? Eg. Yardstick gem seems to not work with 1.9.2 but perfectly with 1.8.7. H...

Ruby/Rails Conditional search method (if ... else "no results found")

Hi, Here is the code of a "simple search form" (thanks to jordinl) which I try to improve. I would like to add the case if there is no match found. So, there is the view (views/users/index.html.erb) <% form_tag users_path, :method => 'get' do %> <%= text_field_tag :search, params[:search] %> <%= submit_tag "Search", :name => nil ...

Rails::Railtie: Trouble creating a Rails 3 gem

I could really use another set of eyes on this so I thought I would post it here. A while ago I wrote a basic ActiveRecord Extension for my own educational purposes. I've been reading about Railties lately and thought I would try to get it working with Rails 3. I thought I would package it up as a gem to get a sense of that process as we...

Recommended rdf usage in Ruby on Rails

I'd like to publish rdf in my rails apps. What's the right way to do it? ...

Generators with rails 3 and rspec 2

I installed rails 3 with rspec 2, but when i run controller generator it creates rspec tests only for controller helpers and does not create them for controller itself. ...

How do you examine the source code?

How do you examine the source code for a library you are using and want to modify. Eg. when you have downloaded a gem, I guess that you are forking the repo from GitHub and then cloning your forked repo. So now you have: the local repo's source code (which you open with IDE/text editor) the source code on GitHub (which you browse onl...

Better way to write if condition in ruby.

if args.size == 5 value_for,alt_currency_id,amount,exchange_rate_code,tran_dt = args else value_for,alt_currency_id,amount,exchange_rate_code,year_no,period_no = args end Any Better way to write this condition ?? ...

Ruby: How to load a WSDL file into some data structure?

I have a WSDL file and want to load it into ruby somehow so I can navigate through it. Anyone know how to do this? ...