ruby

Rails best practice to check an object's existence before displaying an attribute in a layout

I have the following code in a layout: Posted <%=time_ago_in_words post.created_at %> ago <% if post.has_tag != nil %> in the <%= post.get_first_tag.name %> category <% end %> And the following code in the post model which is inheriting form ActiveRecord::Base def has_tag !self.tags.empty? end def get_first_tag self.tags[0]...

Restrict ActionMailer to one domain

I have a rails application running in a staging-environment, which is an accurate copy of the production. I would like to be able to send mails with ActionMailer, to test that it all works as it should, but to prevent any mistakes, I would very much like to be able to restrict the mailer from sending out to any addresses that are not on ...

Easy question: Read file, reverse it and write to another file in Ruby

I have: o = File.new("ouput.txt", "rw+") File.new("my_file.txt").lines.reverse_each { |line| ????? line } o.close I don't know what method to use to write to the file output o ...

Safely & efficiently sort on a possibly-missing attribute?

Here's what I'm doing: offers = v.offers.sort { |a,b| a.expires <=> b.expires } This data is loaded via ActiveResource (so each set of instance attributes is defined by the data it contains). However, a recent change in the incoming data has made the "expires" attribute optional. Is there a class definition change that will cause the ...

how to add a param to xslt with xslt-ruby?

the title states it, essentially what is wrong here? I keep getting nothingness the param isnt getting passed... <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:param name="stylesheet"/> <xsl:template match="/"> <xsl:copy-of select="$stylesheet"/> </...

Rcov coverage changes drastically with -xrefs

My current Ruby on Rails project does testing via rcov (specifically, relevance rcov, and we have a pretty high standard (we fail the build if we have < 95% code coverage). We use the following command to test this: rcov_cmd = "rcov --rails --text-summary \ --include #{included_dirs} \ --exclude #{excluded_dirs}...

One liner to limit Array of Words to less than N number of characters in Ruby?

What's the simplest way to limit an array of words such that the resulting array, when the words are joined, is less than 40 characters? Something that acts like this: words = ["ruby", "rails", "jquery", "javascript", "html"] words.join.length #=> 29 words.join(", ").length #=> 37 words = ["ruby", "rails", "jquery", "javascript", "html...

Problem with ruby class

I've got a problem with this class require "test/unit" require "selenium/client" class Test < Test::Unit::TestCase def setup @verification_errors = [] @selenium = Selenium::Client::Driver.new \ :host => "localhost", :port => 4444, :browser => "*chrome", :url => "http://change-this-to-the-site-you-are-...

Why am I getting a segmentation fault with the SQL Server ActiveRecord adapter?

isql runs just fine: kobey:/etc# isql -v censored censored censored +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | ...

How do you define the same tasks differently for different roles in Capistrano?

I'm using Capistrano to handle my deployment, and I've got two different roles in my setup - :web and :processing. They both have the usual :deploy tasks, but the :restart task needs to be different for the two types of server. So my first attempt was something like this: task :restart, :roles => :web do run "... web related restar...

Build error 71 on X-Code

Hi Guys, I've been working on a GUI program for a while now, and I just can't get it to compile correctly, I am constantly receiving the following error - Command /Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copystrings failed with exit code 71 I've done some searching around to try to find a solution, ...

What Ruby template parsers are there besides ERB and HAML?

What (preferably stable releases) alternatives exist to ERB and HAML for creating a HTML template parser with Ruby? I would really love something like Django templates implemented in Ruby. ...

Ruby - overwrite def method

Hi, How can I overwrite the def method? But it's strange, cause I don't know from where the def method is defined. It's not Module, not Object, not BasicObject (of Ruby 1.9). And def.class don't say nothing ;) I would like to use something like: sub_def hello puts "Hello!" super end def hello puts "cruel world." end # ...an...

building ruby on windows 7

I know this has been asked before but I ran into a specific problem. I'm trying to build ruby 1.9.2 rc2 on windows 7. When I run configure.bat it aborts with the following message. cl -nologo -MD rtname.c user32.lib -link > nul NMAKE : fatal error U1077: 'cl' : return code '0x2' Stop. I find that the file 'rtname.c' does not exist an...

how can I make a drop down list in Rails 2.0?

Hi I have two models in Rails: invoices and products. Each invoice has one or many products. And each product belongs to one or many invoices. On the invoices view, I would like to select the product name in a drop down list. The list needs to contain all the products available. If I insert another product in the product view, this new...

Session problem using Facebooker with Ruby on Rails

Hey everybody, I am reading the book Facebook Platform Development in order to try to code a small game for Facebook, and I have come across a "little" problem: I am trying to insert a user every time this is logged, into a database in my computer. I am using a couple of methods written in the book, but there seems to be a couple of pro...

Changing the RoR SQL call to NAME instead of *

Being that it is better to call a SQL database with the specific item, for example: Bad: SELECT * FROM tblUsers Good: SELECT email FROM tblUsers How would I do this in RoR to make it explicitly perform the latter example? ...

What is causing this difference between my Ruby on Rails console output and my Firebug console output when using a Ruby date object?

Can anyone explain the difference between the Ruby on Rails console output and the Firebug console output? event_controller.rb def list_events @days[1][:date] = (((Date.new(2010, 8, 6)) + 1).to_s) end list_events.html.erb <% @days.each_with_index do |day, i| %> <% p day[:date] %>; //RoR console console.log(<%= day[:date]...

Renaming XML elements in Ruby?

How does one go about renaming an XML element using REXML or another Ruby library? Thanks for any advice. ...

How can I install Jekyll on Ubuntu 10.04 Server?

The definitive guide to installing Jekyll seems to be http://wiki.github.com/mojombo/jekyll/install where it says: gem install jekyll I am getting an ERROR: could not find gem jekyll locally or in a repository regardless of whether I run that command as superuser or not. gem env Returns the following: RubyGems Environment: - RU...