ruby

skipping after_update callback

I have a model that uses after_update to log changes. There is a case where I would like to make a change to the model without activating this logging mechanism. Is there a way to pass in a parameter to after_update, or skip it all together? I would like a nice solution to this, and am willing to remove after_update if there is a better...

Opposite of Time.now.advance() in Ruby

http://rails.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Calculations.html#M001139 documents a method advance() to add to the current time. Is there an opposite, 'go_back() method? ...

Ruby: how do I recursively find and remove empty directories?

I'm trying to write some ruby that would recursively search a given directory for all empty child directories and remove them. Thoughts? Note: I'd like a script version if possible. This is both a practical need and a something to help me learn. ...

Phusion Passenger with Ruby 1.8 and 1.9 ?

Hi, How would I go about running two separate Rails applications using Phusion Passenger with one using Ruby 1.8.x and the other using Ruby 1.9.x ? I'm running Redmine which isn't Ruby 1.9.x compatible, and the other application is a home grown app. I'm using Apache 2.2.x with Passenger 2.2.4. Is this even possible ? ...

Forcing "+0000" timezone for RFC2822 times in Ruby

How can I force the Time.rfc2822 function to spit out +0000? Ruby lets me parse RFC2822 formatted times pretty easily: require 'time' time = Time.parse('14 Aug 2009 09:28:32 +0000') puts time => "2009-08-14 05:28:32 -0400" But what about displaying times? Notice that the time it parsed is a local time. No worries, I can convert it ...

Authlogic openid with multiple openid identifiers per account

How would you go about allowing a user to log in with multiple openid accounts and optionally a password, using authlogic? ...

Class returning an array

I have a class like: class Configuration def self.files @@files ||= Array.new end end Now instead of doing this: irb(main):001:0> Configuration.files => [file, file, file] I would like to be able to do this: irb(main):001:0> Configuration => [file, file, file] But I can't figure out how, any ideas? @glenn jackman: I...

For some reason config.gem 'xapian-fu' fails despite gem 'xapian-fu' works?

For some reason when I try to do config.gem include for this particular gem package it always says its missing. I tried gem 'xapian-fu' and that works just fine! I am sure its not multi gem repository issue as I use the environment in regular basis and has no problem about this. ...

Logging out after authenticate_or_request_with_http_basic in rails

How do I "log out" a user? Know that this is not officially supported, but I need a quick and dirty hack. Saw somewhere I just throw out a 401 access denied - but anyone know the syntax ...

How do I impersonate a user with AuthLogic

I need to be able to create a UserSession without having the decrypted password. How do I go about doing this? My current workaround is: In user.rb def valid_crypted_or_non_crypted_password?(password) valid_password?(password) || password == crypted_password end In user_session.rb verify_password_method :valid_crypted_or_no...

Shoes: Element.width return 0

I don't understand why the width function is implemented on all elements if it returns 0 for non-zero width elements. The following returns 0 for me. Shoes.app do p = para "My width is: " para p.width end Why is that? (app.width does not return 0) ...

Rails: Smart text truncation

I wonder if there's a plugin to enable a sort of smart truncation. I need to truncate my text with a precision of a word or of a sentence. For example: Post.my_message.smart_truncate( "Once upon a time in a world far far away. And they found that many people were sleeping better.", :sentences => 1) # => Once upon a time in a w...

watch / read a growing log file with ruby

I have a log file that is constantly growing, how can I watch and parse it via a ruby script. The script will parse each new line as it is written to the file and output something to the screen when the new line contains the string 'ERROR' ...

How do I create an arbitrary link in YARD documentation?

I'm trying to create some links in my YARD documentation. I can get an HTTP link: # I like {http://stackoverflow.com Stackoverflow} renders as <p>I like <a href="http://stackoverflow.com"&gt;Stackoverflow&lt;/a&gt;&lt;/p&gt; But an email link: # You can email the {mailto:[email protected] bugs} list gives me a warning: [warn]...

How to make an element take up all-the-width-that-is-left?

Shoes.app do flow do file = "something with variable length" para "Loading #{file}: " progress :width => -300 end end As you can see from the code I am trying to display a progress bar that goes from the end of the text until the right edge of the application window. When the text has a fixed length this solution works ...

How to diff multiline strings with RSpec?

I am generating some XML using a builder, and would like to compare the results to some file contents. However, since the strings are so long, the output is hard to read when the strings differ. I know there are a number of libraries for diffing strings in ruby, but is there a built in facility in rspec for generating multiline string ...

Executing Ruby script in an Rails application

I can run the following commands in the console for my Rails application and import CSV file into my database. require 'csv' # row will be an array with the fields in the order they appear in the file CSV.open('myfile.csv', 'r') do |row| # assuming the fields in the CSV file are in order npa, nxxFrom, nxxTo, trnk # create and s...

Why do I lose my instance variables when I invoke Shoes#'visit' ?

I'm sure this has to do with the intricacies mentionned in Shoes > Manual > Rules but I just don't get it. If someone would care to explain why @var == nil in the following code ... I thought I could use visit to switch between different views in my application but that won't work if I lose all state. class MyShoe < Shoes url '/', :i...

show products in category in a new page

I have a problem in Rails, I want to show products in each category on a separate page when user clicks on the proper link, categories and products have HABTM relation, I can see the results but I don't want to show them in default pages(routes). Should I create a new routes rule or this can be achieved in controller and view without edi...

scoped_by greater than or less than in ActiveRecord (Rails)

I want to use a dynamic scope in Rails where I filter by date. I want to do something like this: Foo.scoped_by_created_on(>the_future).scoped_by_created_on(<the_past).find(:all) Is this possible or am I stuck writing a :conditions hash? ...