ruby

Getting 500 Error when trying to access Rails application through Apache2

Hey, I'm using Apache2 as proxy and mongrel_cluster as server for my Rails applications. When I try to access it by typing in the url I get a 500 "Internal Server Error" but when try to locally access the website with "lynx http://localhost:8200" it works. This is my config: <Proxy balancer://sportfreundewitold_cluster> BalancerMember...

How to expire a caches_action with a cache_path?

I'm caching an index action with the following: caches_action :index, :cache_path => Proc.new { |c| c.params } expire_action :action => :index The expire_action seems to only expire the index action without any parameters. How can I expire all the caches_action related to index ? (it is a Rails 2.3.5 application) ...

Can I add text to page-source dynamically in Ruby on Rails.

Hi, I would like to add text dynamically to the page source in a particular view. I checked the IO streams, but couldn't find anything. Could you please provide some pointers. Edit: Thanks for the reply. I was trying to know how much time each part/component in a particular view takes to render and log it as part of the page-source. P...

NoMethodError using Memcached Sinatra-style

I've just installed Memcached on my Mac and updated my Sinatra app configuration as described in Heroku's documentation, but I'm getting a NoMethodError when trying to use the hash-based syntax they specify: >> CACHE['color'] = 'blue' >> CACHE['color'] Using explicit get and set methods as below seems to work fine. >> CACHE.set('colo...

Generating link path with parameters

Hi. I've got model with many associations. User :has_many => :posts, :videos, :images etc I've got helper method, which receives one of this association draw_chart user.videos def draw_chart(assoc) assoc.each do |a| link_to "update", [a.user, a], :method => :put, :remote => true, :confirm => 'orrly?' end end Problem here is...

Validating "Visa Debit" cards in ActiveMerchant

How can I correctly validate a Visa Debit card in ActiveMerchant? At the moment, the card fails to validate despite it being a valid card number. I have tried using :visa, :visa_debit and nil card types. ...

IRB and large variables?

How can I print a large variable nicely in an irb prompt? I have a variable that contains many variables which are long and the printout becomes a mess to wade through. What if I just want the variable names without their values? Or, can I print each one on a separate line, tabbed-in depending on depth? ...

Ruby, RoR, gmail and NET::SMTP

Is there any way to use gmail as a smtp server on rails 2.3.5/ruby 1.9.1? My smtp settings for actionmailer are options = { :address => "smtp.gmail.com", :port => 587, :domain => 'REMOVED', :user_name => 'REMOVED', :password => 'REMOVED', :authentication ...

How to access original command-line argument string in Ruby?

I'm trying to access the original command line argument string in Ruby (ie - not using the pre-split/separated ARGV array). Does anyone know how to do this? For example: $> ruby test.rb command "line" arguments I want to be able to tell if 'line' had quotes around it: "command \"line\" arguments" Any tips? Thanks in advance ...

Ruby equivalent to .NET's Encoding.ASCII.GetString(byte[])

Does Ruby have an equivalent to .NET's Encoding.ASCII.GetString(byte[])? Encoding.ASCII.GetString(bytes[]) takes an array of bytes and returns a string after decoding the bytes using the ASCII encoding. ...

Ruby / Installation Package - What is the fastest way to setup a Ruby environment in Windows?

I currently work in a LAMP environment and use XAMPP to setup my dev environment in Windows. Are there similar installers that package all of the essential and commonly-used Ruby development tools? ...

Finding the highest, lowest, total, average and median from an array in Ruby

I am creating a boxplot generator in Ruby, and I need to calculate some things. Let's say I have this array: arr = [1, 5, 7, 2, 53, 65, 24] How can I find the lowest value (1), highest value (65), total (157), average (22.43) and median (7) from the above array? Thanks ...

Rails - Accessing model class methods from within ActiveRecord model

I have a simple standalone model that doesn't inherit from ActiveRecord or anything else, called SmsSender. As the name suggests, it delivers text messages to an SMS gateway. I also have an ActiveRecord model called SmsMessage which has an instance method called deliver: def deliver SmsSender.deliver_message(self) self.update_attri...

What are the disadvantages of AJAX on Rails?

Hi All, what are the scenario's where Ajax could not be used in Rails Application. Is there any disadvantages of AJAX (AJAX on RAILS) if yes please mention which are they? ...

How to get strptime to raise ArgumentError with garbage trailing characters

We have to handle user specified date formats in our application. We decided to go with Date.strptime for parsing and validation, which works great, except for how it just ignores any garbage data entered. Here is an irb session demonstrating the issue ree-1.8.7-2010.01 > require 'date' => true ree-1.8.7-2010.01 > d = Date.strptime '2...

setting cookies

Okay, so I'm trying to set cookies using Ruby. I'm in a Rack environment. response[name]=value will add an HTTP header into the HTTP headers hash rack has. I know that it works. But the following method of setting cookies doesn't work: def set_cookie(opts={}) args = { :name => nil, :value => nil, :expire...

Force current_user path

Currently users can access their "profile" through many paths. localhost:3000/users/current_user localhost:3000/users/current localhost:3000/users/id# How can I make it that they can only get to their "profile" through localhost:3000/users/current_user ...

Which is a better way to detect a client's user-agent?

I am interested if which would be the best place to detect the client's user-agent, client-side (javascript) or server-side? I brought up the question due to the fact that some IE8 users are getting a message saying they're using IE6. ...

which language to choose for a LIVE web application?

i want to create not only a web application, but a web application where everything is LIVE. eg. if someone posts a message and then another one replies, then the creator will get on his webpage a notification. and also i want to implement a chat in the web application. i want these features to be implemented using true server-push (n...

Watir question regarding selecting a hidden dropdown.

Hi, I have two dropdowns, the second dropdown does not show until a choice is made from the first one. Using watir, i can select the first dropdown, and when i watch it, the second one becomes active, but it cannot select it. i just tried the regular select_list using name and id. Here is the code for the second drop down. <td> <input t...