ruby

Is Rails 2.3.8 or Rails 2.3.10 fully compatible with Ruby 1.9.2? (any reference or source say that?)

because if those Rails versions were not written with 1.9.2 in mind, then there might be slight usage difference that can break Rails. Actually, can any gem command tell a particular gem is dependent on what versions of other gems (and perhaps Ruby version too)? ...

How to pass YML-like data struct to scenario of cucumber ?

I want to pass YML-like config data to the scenario of cucumber. for instance: category: subcategory: name: whay how to do this? thanks ...

Ruby/Rails: Determine variables from plain text to update via form

I'm creating an app where users can edit their own CSS (in SCSS syntax). That works fine, however, I eventually want these CSS files to be "programmable" so that users that don't know CSS can still edit them in a basic manner. How? If I can mark certain things as editable, I don't have to make an impossible database schema. For example ...

Rails cannot cache precalculated values across browser requests? (such as remembering n factorial results)

For example, the following code: class FoosController < ApplicationController def index if [email protected]? render :locals => {:bar => @foo} return else @foo = rand 10 render :locals => {:bar => @foo} end end end if I load localhost:3000/foos multiple times, it will show different values, and it is n...

In Ruby, why after starting irb, foo.nil? says undefined error, and @foo.nil? gives "true", and @@wah.nil? gives error again?

Same in Ruby 1.8.7 and 1.9.2: $ irb ruby-1.8.7-p302 > foo.nil? NameError: undefined local variable or method `foo' for #<Object:0x3794c> from (irb):1 ruby-1.8.7-p302 > @bar.nil? => true ruby-1.8.7-p302 > @@wah.nil? NameError: uninitialized class variable @@wah in Object from (irb):3 why the instance variable treated diffe...

email encoding and sending through SMTP - Ruby

Hi Everyone, I have run across an interesting problem. I am sending email with attachments through the NET::SMTP class in ruby through Apple's me.com SMTP servers and I am running into some funny issues. I am trying to send a series of jpg files through the SMTP server. I am encoding them in ruby and when I send to another me.com emai...

Cucumber: Events should be listed in chronological order by event date

This cucumber-test wont fail even if I replace the order of the events. It should only pass if the order is in the chronological by event date. But its passes in whatever order i put the table in. What can the problem be? Scenario: Events should be listed in chronological order by event date Given I am signed into an account called "Gor...

Can an object's methods act on itself?

I'm not sure where to put some methods. Let's say I want to send an email. Which of the following options should I choose: email = new Email("title", "adress", "body"); email.send(); or email = new Email("title", "adress", "body"); Postman.send(email); Because how can an email send itself? And isn't it better to have a central ob...

Given a Model, how to loop through all properties?

I want to loop through all the properties of my 'user' model, how can I do this? ...

Paperclip and failed validation - avoid reupload

Hello, I am currently setting up Paperclip for a model with Rails 3. When one of the fields fails validation (title), the user has to upload the file again. This is not very user friendly :/ The recommendation from the Paperclip forum is to move the Paperclip stuff into a related model. My model is very simple with just a few fields, ...

Rails routing for render xml gives 404

I'm facing a problem I don't really understand. This is my controller def index @resources = Resource.all(:limit => 10) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @resources } end end When i try to access the html page, everything works fine, but when i hit the .xml ...

Rails parameters from GET/POST

Hi, I'm fairly new to Rails and am writing a login form. I have used form_tag to pass through the user's submission to the account controller. Now, I don't want the user to be able to enter their login details through a GET request, so how can I check that a certain param is either a GET or POST parameter? Thanks in advance ...

How to get Capybara to see Javascript in plugin directory when creating plugins?

We're developing a plugin for rails, and I've got Cucumber working with Capybara wonderfully. BUT, when developing, I've been (erroneously, I guess) putting the Javascript files in the parent test application's public/javascript directory. So when Capybara runs, it doesn't find the javascript file. How can we get Cucumber/Capybara to see...

Consuming Web Services in Ruby that use reserved words as field names

I'm attempting to consume a WebService where one of the complex types in the WSDL has a field name that uses a Ruby reserved word. When I call a method returning one of these complex types and attempt to access the data, I get an error. How can I consume this web service that uses a reserved word in Ruby? The relevant section of the...

Rspec and Infinity Test in color

I am using infinity_test gem with rspec in a rails project. How can I get the output in color? I tried setting in terminal rspec --color I then ran "rspec spec/" to make sure color output was working. Then I run infinity_test and the test output is no longer in color. How can I get it to output in color? ...

I can't install any gem or updates in Leopard

bogon:~ Zhulin$ ruby -v ruby 1.8.6 (2009-06-08 patchlevel 369) [universal-darwin9.0] bogon:~ Zhulin$ rails -v Rails 1.2.6 bogon:~ Zhulin$ gems -v -bash: gems: command not found bogon:~ Zhulin$ sudo gem install heroku Password: ERROR: While executing gem ... (Gem::RemoteSourceException) HTTP Response 302 fetching http://gems.rubyforg...

Receiving error on Windows machine when Installing linecache ERROR: Failed to build gem native extension on

When attempting to perform a bundle install of an existing Ruby on Rails project I receive an error when the bundler reaches Installing linecache (0.43) with native extensions. I don't see linecache in the projects Gem file so I can't try bundling without it. I'm running Windows 7 and JetBrains RubyMine 2.0.2. I have tried bundling from ...

Ruby while syntax

Does anybody why I can write this: ruby-1.8.7-p302 > a = %w( a b c) => ["a", "b", "c"] ruby-1.8.7-p302 > while (i = a.shift) do; puts i ; end a b c => nil Which looks like passing a block to while. And not: while(i = a.shift) { puts i; } Is it because the "do" of the while syntax is just syntaxic sugar and as nothing to do with...

Parsing XML with REXML

I have this XML document and I want to find an specific GitHubCommiter using REXML. Hoy do I do that? <users> <GitHubCommiter id="Nerian"> <username>name</username> <password>12345</password> </GitHubCommiter> <GitHubCommiter id="xmawet"> <username>name</username> <password>12345</password> </GitHubCommiter> <GitHubCommit...

how to change the value of Date.today within a running ruby process

Hi, I know this is a bad idea, but I have lots of legacy code and I want to run through some historical batch jobs. I dont want to change the systems date because other stuff runs on the same system. Is there any way that I can change the value that Date.today will return for the life of a given process only. The idea here is to rewind a...