ruby

Easiest way to "goto source code" for Ruby/Rails

As a Ruby/Rails non-pro, I often want to check out the code for a rails method to see how it's implemented... For example, I was using "form_for", and I wanted to check out the code to see how it works. The slightly lame way I did this was to just google "rails form_for" which takes me to http://api.rubyonrails.org/classes/ActionView/H...

ActiveSupport requires Ruby version >= 1.8.7 on Ubuntu

Hi, I'm currently setting up a new server, and started off with an Ubuntu 8.04 image with a version of Ruby and Rails already preinstalled (I thought it would be easier), and after getting my app running (with a few gems installed), the command line is throwing a wobbly, and trying to install the "Paperclip" gem, is giving the following ...

How can I write this more "ruby-ish"?

Hi folks I got the following snippet Class Artist < ActiveRecord attr_accessible :solo #boolean def change_solo! if self.solo == false self.solo = true else self.solo = false end self.save end end Is there a better way to write that? Thanks in advance cheers tabaluga ...

calling a super class' method with a twist

Suppose I have two classes like so: class Parent def say "I am a parent" end end class Child < Parent def say "I am a child" end def super_say #I want to call Parent.new#say method here end end What are the options to do that? I thought of: def super_say self.superclass.new.say #obviously the most straight fo...

Using calendar_date_select with Rails 3

I've been trying to create a user date-of-birth selection field during sign up. The code looks like this: <div id="content"> <h3>Register</h3> <%= form_for(@user) do |f| %> <div style="width: 374px; margin: 0 auto;"> <%= f.label :name %> <%= f.text_field :name %> <div style="clear: both;"></div> <%= f.lab...

Sinatra requires restart

I'm just getting started with Sinatra. I'm running Ruby 1.9.2 on Ubuntu. After my first issue, I've run into another one: When I follow the simple sample application instructions at sinatra.rubyforge.org/doc/, I modify my source file, but the changes aren't apparent until I restart Sinatra - even though the tutorial mentions there is n...

Using cucumber with staging database without truncation and transactions

We have a Ruby on Rails 2.3.8 project, where data are almost exclusively read only. We would like to write acceptance tests which use staging database (copy of the production database) So we do not want to use transactions or truncation of the database tables before or after features and scenarios. Is it possible? ...

Ruby YAML write without aliases

I am writing data to yaml files from ruby and I frequently get aliases dotted about the file. Things like: - &id001 somekey: somevalue - *id001 In my case I am using the yaml files to aid readability and add names to values in the files as the existing data is just | separated values with no keys. How can I prevent the yaml files ...

detect cjk characters in a sentence using ruby!!

$str = "This is a string containing 中文 characters. Some more characters - 中华人民共和国 "; How do I detect if there are chinese characters in this string but i have no idea how to do it.Any clues? ...

Testing Applications built on top of RESTful web services

Lets say; I am developing a Web Application which talks to a RESTful web service for certain things. The RESTful web service isn't third party, but is being developed parallely with main application (A good example would be, E commerce application and payment processor; or Social network and SSO system). In such a system, acceptance(c...

Does Windows 7 hide files from Ruby?

I am trying to run the program nbtstat.exe(located in c:\windows\system32) from a ruby script. The problem is that it appears that Windows 7(64-bit) is hiding the program from the ruby script(it works fine in Vista). For example, Nbtstat command: "nbtstat" Dir command: dir "C:\Windows\System32\n*.exe" If I run the nbtstat command in ...

Postinstall, rvm(ruby version manager) without root access.

I am trying to use rvm(ruby version manager) and after the source installation, I need to add rvm command into my profile. I added following code to the $HOME/.profile file but it does not seem to work. [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session. So I just manually typed bel...

rails i18n help please

hi all i have added internationalization to my site via domainname.com/en/etc I have done this by adding to map.with_options(:path_prefix => ":locale") do |m| to wrap around all my resources in routes file. I have added this to application_controller before_filter :set_locale def set_locale # if params[:locale] is nil then I18...

nanoc site tested with unicorn

Hello, I have a nanoc site (so, all static pages) that I'd like to test with unicorn. The idea behind this is to host this site on heroku then. The structure is then a rack application. I have added a config.ru file like: require 'rubygems' require 'rack' require 'rack-rewrite' require 'rack/contrib' use Rack::Rewrite do rewrite '/','...

how to pass a Ruby iterator as a parameter?

I'd like to write a method that yields values in one place and pass it as a parameter to another method that will invoke it with a block. I'm convinced it can be done but somehow I'm not able to find the right syntax. Here's some sample (non-working) code to illustrate what I'm trying to achieve: def yielder yield 1 yield 2 yiel...

Accessing "Google Documents List API" via AuthSub returns "Invalid AuthSub token"

I'm trying to retrieve the list of documents (from Google Docs) as an XML feed via ruby's net/http. So getting an AuthSub token works pretty well, then the issues begin... No matter what I'm trying, I'll always get Token invalid - Invalid AuthSub token as a response. First of all, I'm requesting the AuthSub login stuff in the browser vi...

Retrieving data from API and display it.

I have a link which is returning data in xml. I don't know how may i fetch data from api and display it. I want to fetch data from provided link like http://api.testdata.co.in/a/pn-1?koid=1234&amp;dfr=12.14.127.10 . Any help ? ...

Get first few elements of a html fragment with xpath on ruby

For a blog like project, I want to get the first few paragraphs, headers, lists or whatever within a range of characters from a markdown generated html fragment to display as a summary. So if I have <h1>hello world</h1> <p>Lets say these are 100 chars</p> <ul> <li>some bla bla, 40 chars</li> </ul> <p>some other text</p> And assum...

500's, timeouts, and redirect loops with Radiant (a RoR CMS)

I'm struggling to get a simple CMS website up and running but can't get past the installation stage. I've been working on this off and on over 4 days and am getting burnt out and demotivated on the project. To summerise my pains: I keep getting Redirect loops and FCGI timeouts no matter what I do. Unfortunatly I've never touched Ruby, R...

schedule_fu locks mysql up

I've been using schedule_fu for recurring events but I keep getting this Mysql::Error: Lock wait timeout excedded. Anyone else experienced this problem or do you know what causes a Mysql::Error like this. I'm using Rails 2 and developing on OS X. SQL (0.1ms) BEGIN SQL (0.1ms) SAVEPOINT active_record_1 CalendarDate Create (0.0ms)...