ruby-on-rails

Ruby on Rails - Using Timezones in Rake Tasks set for Cron Job

My web application requires 6 different cron jobs to run to update timezone sensitive data within tables at 00:01:00 of each timezone. I want to create rake tasks for each time zone. Can I configure rake tasks to be timezone aware? For e.g., can I do that following in a rake task: namespace :db do task :update_EST_records => :env...

Kill all delayed_job workers

I use delayed_job as a daemon http://wiki.github.com/tobi/delayed%5Fjob/running-delayedworker-as-a-daemon. I can't tell why, but sometimes I see more than one job done by several workers (different pids), and running stop doesn't stop anything. is there a way to kill all daemons of this proc/all workers? Or kill a specific pid (I'm on a...

Why aren't my ruby processes exiting on my FastCGI shared server when using send_file?

After developing an awesome app on my local machine without any consideration of how it would perform on my host, I have run into a terrible issue. I am serving files (.pdf & .zip) through rails send_file so that I can log statistics. The only problem is that when two (or more) files are downloaded simultaneously, a new ruby dispatch.fcg...

Authenticating an iPhone app with web backend

I'm just fleshing out some ideas for an iphone web app and it's going to be (in essence) a CRUD interface to a Rails web backend. Ultimately that backend will be a full blown website too. My question is: what's the best way to handle "logging in" on the iPhone app? How should it authenticate to allow the user to see their data and add n...

How to make a generic redirect when accessed to a / declared in the routes.rb on Ruby on Rails

I have several urls declared in the routes.rb, such as aaa/index.html aaa/bbb.html bbb/index.html bbb/ccc/index so it looks like a non-rails site. I want it so that when a user accesses aaa/ or bbb/ccc/ they would automatically be redirected to the action routed to the index.html of the corresponding directory. currently I am writ...

Sanitizing User Regexp

I want to write a function that allows users to match data based on a regexp, but I am concerned about sanitation of the user strings. I know with SQL queries you can use bind variables to avoid SQL injection attacks, but I am not sure if there's such a mechanism for regexps. I see that there's Regexp.escape, but I want to allow valid re...

Getting Hoptoad to work in a staging environment

I have an action which causes an exception in my staging environment, but instead of sending the notification to hoptoad (which it should, the hoptoad test rake task works...), it shows me the standard rails stacktrace page like it does in development. My staging environment is essentially a copy of my production environment with the on...

Rails friendly error page in development.

In my config/environments/development.rb I have the following line: config.action_controller.consider_all_requests_local = true which means I should get all the ugly error stuff when in development environment. But for some reason my app has suddenly started giving me the pretty error page you're supposed to see on production. Is the...

RubyGems Environment (Snow Leopard)

Greetings, My question is why do I have 3 separate gem paths. My 'gem environment' command displays the following: GEM PATHS - /Library/Ruby/Gems/1.8 - /Users/adam/.gem/ruby1.8 --This one makes sense to me - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 Why the two separate "system" paths? Thanks...

time_ago_in_words issue

I have an issue that I just ran into (for some reason) using time_ago_in_words. After publishing a post, I got translation data {"one"=>"1 minute", "other"=>"{{count}} minutes"} can not be used with :count => 9 I am not really doing anything that interesting either, just calling a small helper function def friendly_publish_date(post)...

Rails Generate Model from Existing Table?

Hi guys, I'm very new to the rails framework and want to know how to generate a model based on an existing table. For example, I have a table named person and want to generate the model based on the columns from that table. However, whenever I use "ruby script/generate model Person --skip-migration it creates an empty table named people...

Cucumber + webrat + selenium, how do I ignore hidden text?

I am using Cucumber, webrat and selenium to test a web application. I use 'I should see "something"' to verify changes. However, in many places, text to be verified only changes from hidden to visible (this might be caused by removing 'hidden' class from itself or one of its ancestors). In this case, above test does not actually verify t...

Database Relationship in JSP like Ruby-on-Rails

In ruby on rails we can specify many Database relations line belongs_to, has_many, and this make coding a lot simpler. But is there any such database relationship APIs that brings such coding ease to JSP. I'm pretty new to JSP. But you can relate any code with ROR. ...

(Rails) Using helper methods to perform Ajax filtering...?

Hi All, I'm looking to filter a list of items using a created helper method instead of a controller method. I see that it's possible to dynamically manipulate a view using prototype helpers from within a helper. However, I'm not sure how to use a text field in combination with "observe_field" in order to properly pass the parameter to...

Authlogic/OpenID Authentication Fails Using Warp Drive

Warp Drive is a nice way to package an entire Rails application into a Gem for use in other Rails applications. I've gotten Warp Drive to work for a blogging engine I'm creating. There's just one problem - Authlogic OpenID authentication fails. I created a bare-bones OpenID example application. I can compile to a gem with no problems: ...

Strange routing problem in link_to; gotta be something simple

My brain is fried trying to squeeze some work in before the holiday. I'm trying to fix a simple bug. The URLs that the following link_to_remote is creating are wrong: options = { :url => { :controller => 'favorites', :action => 'resort', :params => params.merge({:sort => key, :method => method})}, :update => 'favorites' } html_...

Adding credit card errors to `errors` when using activemerchant

I followed the railscast on activemerchant and have this code: def validate_card unless credit_card.valid? credit_card.errors.full_messages.each do |message| errors.add_to_base message end end end But that doesn't wrap the field in a fieldWithErrors div. So I tried: def validate_card unless credit_card.valid? ...

Difference between RR mock.instance_of and Mocha any_instance

I have the following rspec code: require 'spec_helper' require 'mocha' require 'rr' describe ProjectsController, "creating a new project" do integrate_views it "should redirect to project with a notice on successful save" do Project.any_instance.stubs(:valid?).returns(true) #mock.instance_of(Project).valid? {true} Proj...

How to set locale default_url_options for functional tests (Rails)

In my application_controller, I have the following set to include the locale with all paths generated by url_for: def default_url_options(options={}) { :locale => I18n.locale } end My resource routes then have a :path_prefix = "/:locale" Works fine on the site. But when it comes to my functional tests, the :locale is not pas...

ruby on rails: how to change BG color of options in select list

Hi, I want to pull list of colors from model and put the color select list in the view. Options have value as color code. I want to change the background color of options same as its value. Below are two ways I tried to do but it comes out that it changes color for whole select list but not for individual options with individual colors....