ruby

Ubuntu and Ruby version

I have Ruby versions 1.8.7 and 1.9.1 on Ubuntu. How do I get the system to register Ruby 1.9.1 when using ruby -v? ruby is at /usr/bin/ruby ruby1.9.1 is at /usr/bin/ruby1.9.1 Also, can someone recommend a free text editor for Ubuntu? ...

Installing RVM (Ruby Version Manager)

Hi, Can someone please translate this into manageable steps I need to take: ~ Wayne You must now finish the install manually: 1) Place the folowing line at the end of your shell's loading files(.bashrc or .bash_profile for bash and .zshrc for zsh), after all path/variable settings: [[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME...

How to parse a quoted search string using regex?

Given a search string "cars 'cats and dogs' fish 'hammers'", what's the best regex for capturing all search terms. It should support single and double quotes. A Ruby friendly answer if possible. ...

Given "T, total number" and "N, number of days", how to divide T by N so that n1 + n2... equals T in an exponential curve?

I'm creating dummy data for an app, and want to simulate exponential growth while also knowing the final number. So here's the proposal: Given T = 2000. Total number of "counts" an event will have occurred. And N = 7. Days of the week: 7.days.ago.day..Time.now.day. What is the simplest formula for dividing T by N such that we create...

Exit status of process started with open()

What is the exist status of a process opened with open() e.g.: f = open("|#{cmd}", 'r') while char = f.getc do something ... end f.???? ...

Rails link_to_remote rendering nothing, why?

RoR newbie here. Working the "play time" exercises at the end of Agile Web Dev with Rails, chapter 9. Can't get link_to_remote to generate a link for me in a partial. My store_cart_item.html.erb partial looks like this: <% if cart_item == @current_item then %> <tr id="current_item"> <% else %> <tr> <% end %> <td> <!-- stuck her...

reverse engineer ActiveRecord data model to jpa

are there any tools which would read a data model exposed via ActiveRecord and generate equivalent data model using JPA? note: We don't have any experience with ruby ...

Login using headers in cucumber

I'm new at cucumber and capybara so maybe this is easy. I'm using headers to check if a user is logged in or not and i'm having a problem when doing cucumber testing. I use Capybara and Cucumber and a "add headers hack": http://aflatter.de/2010/06/testing-headers-and-ssl-with-cucumber-and-capybara/ The problem I have is that it only ...

How to count the object number instead of getting all object in Ruby?

For Example, I want to know the User have how many post. So, I do it in this way; user.posts.length It works, but when I see the server log, it shows me that: SELECT * FROM "posts" WHERE ("posts".user_id = 6) actually, I need to know the post number only, how can I do this? Thank you. ...

Rake can't be found

hey i played around with bundler and some gems and now i can't use rake anymore if i do a simple db:migrate i get this error: mac:app antpaw$ rake db:migrate /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:335:in `bin_path': can't find executable rake for rake-0.8.7 (Gem::Exception) from <internal:gem_prelude>:282:in `method_missing'...

How to map more than one Attribute with ActiveRecord?

Hi Guys, quick question. If I type in my console u = User.first u.friends(&map:username) I geht ["Peter", "Mary", "Jane"] But I also want to show the birthday, so how do I do that? u.friends(&map:username, &map:birthday) doesn't work thanks in advance ...

How to access old state values within datamapper observer?

I'm using dm-observer to observe my dm models, and I need to perform some actions based on state changes within the model. I've figured out that @state is used to store the updated state value, but I have not been able to figure out how to access the old state value. In the example below I've used "old_state", but obviously that does not...

LEFT OUTER joins in Rails 3

I have the following code: @posts = Post.joins(:user).joins(:blog).select which is meant to find all posts and return them and the associated users and blogs. However, users are optional which means that the INNER JOIN that :joins generates is not returning lots of records. How do I use this to generate a LEFT OUTER join instead? ...

Rails - Calling a POST function from server

Hi folks, I need to access a controller level action from another action. This is accessed by the view (so need authenticity token) def post_message #creates the message #normally accessed via webform with authenticity token end def post_via_email #my virtual mailserver calls this method when it receives an email #i need to cal...

how to check the current status of server(up/down) from my rails application

how to check the current status of server(up/down) from my rails application . If server become down,and many users are logined, I need to perform some actions. ...

How can I force Rails to load all models?

Rails does model loading on demand. For a rake task that I'm writing, I need to be able to iterate over all ActiveRecord::Base instances (which is possible with ActiveRecord::Base.send(:subclasses)). However, for the above to work, they have to already be loaded. Anyone know of a way to force all models to load? Ideally I'd like to n...

Auto testing a user's age fails every year

I want to test the age of a user of my Rails application using cucumber. The feature definition look somewhat like following. Scenario: Successful calculation of age Given I set my date of birth to "1987-07-15" Then my age should be "22" Above feature definition will fail every year since the age of user will increase by one each ...

Creating instances with unique attributes using Factory Girl

I have a constraint and a validation placed on the guid field so that each is unique. The problem is, with the factory definition that I have below, I can create only one user instance, as additional instances fail validation. How do I do this correctly so that the guid field is always unique? Factory.define(:user) do |u| u.guid UU...

dispose ruby class object

how to dispose an object in ruby...? class Designer def message "Hello, World!" end end c = Designer.new c.dispose # this is not working... any idea... or any alternative...? thnx... ...

Modules in ruby

module Hints module Designer def message "Hello, World!" end end end p Hints::Designer.message Why this give me the following error...? undefined method `message' for Hints::Designer:Module (NoMethodError) ...