ruby-on-rails

How to return a true/false statement off of a select conditional in rails..

I am trying to select an array, and check and see if any of the objects within the array are false. If any of them are false, I want an ultimate value of false returned. If all of them are true, I want true returned.. Here's what I have.. validates_presence_of :email, :if => Proc.new { |user| user.organizations.find(:all).select {|org...

How to access an array via RJS proxy?

In Rails' RJS Adapter, page['id'] // $('id') accesses an CSS-id, page['id'].property // $('id').property a property of it. But how can I access an array index, e.g. page.select('ul').value_at(2) // $('id').select('ul')[2] Is there any way of doing this without writing: page << "$('id').select('ul')[2]" ...

Phusion Passenger Not always NonBlocking with Rails?

How does Passenger decide when to fork a new process, and can I configure in any meaningful way how many proccesses it should handle (other than "smart" and "conservative" flags in the configuration?) Alternatively, is there any way to debug why a rails app running under Phusion would suddenly freeze up? Background: I'm using Phusion ...

why is this rails route not going to my controller?

This is a follow up to link text about trying to remove the stack trace for routing errors out of my log, and to handle bad routes a little better. Here's my relevant routes.rb entry and controller map.default '*', :controller => 'error', :action => 'route_not_found' class ErrorsController < ApplicationController def route_not_found...

Alphabetical lists with ruby on rails

I am building a list that will be sorted by the alphabet and am looking for a solution to grab the database result and sort it like this: photo Any help is greatly appreciated! ...

Rails 2.3.5 engine (plugin) how to specify gem requirements

When creating a rails engine in 2.3.5 as a plugin, how can the gem dependencies be set within the plugin, without having to import them into the host applications environment.rb? Basically, I need to be able to call "config.gem" after Initializer.run has been called by environment.rb, since the plugin has not been loaded when the confi...

Streamlined way to validate website ownership (with javascript?)

I have a rails app which requires users to verify that they own a website before submitting links from that site. I have implemented a website verification system that works thanks to the answers given to a question I made several months ago. This system works but it is rather cumbersome for users. It requires them to create a web page ...

Rails: Resetting form fields with page refresh

I've got a Rails form that has an observe_field which performs an ajax request when a drop down list is changed. The ajax causes the form to be re-rendered (the form is in a partial) with an extra param that causes some text on the page to change. All that works fine, but when I refresh the page (I'm running firefox), the text is reset a...

How can I re-populate a list in a <div> after adding an item to it using AJAX?

Specifically, I have a number of pages in my Rails app that use the same partial. In the action handler for each page I create an array object (e.g. @list_elements) based on a database query. Each page uses a different query so that each page has different list elements in it. At the top of each page I have a form_remote_tag containin...

ruby on Rails dto objects - Where do you store them?

Does anyone here use DTO's to transfer data from the controller to the view? If so, where would you recommend storing those files? /apps/dtos, and then let them mirror the views dir structure? Any recommendations on testing these animals with rspec? ...

Dynamically set method on before_save.

In my controller i want to dynamically bind my instance method to the before_save callbacks. Is there any ways we can dynamically bind methods to the callback from controller side.... EDIT : Controller This original code.. def amfupdate set_properties validate_record if params[:csv_header][:validate_record] == "Y" #On this cond...

Implementing our billing system in rails: Paypal, pure Merchant Account / Gateway, or something like Chargify ?

I've seen a few questions related to API specifics and paypal. Generally speaking if I'm going to offer my rails app as a subscription based service, what are the pros and cons of the different payment systems available on rails? My main concerns are: Avoiding PCI compliance, and not storing any credit cards on our servers Easy API w...

ruby-on-rails 3 resource handling

Here is my case: I have 3 menus (vietnamese, chinese, japanese) that each contains 10 dishes. I wonder how should i route these to produce one page per menu with its dishes. So that I in the view can have 3 links in the frontpage view, one for each menu. Right now it looks like this: resources :menus But then the index view would ...

ActionMailer, HTML emails and DOCTYPE

I noticed that the examples in the Rails 3 Action Mailer Basics guide use HTML5 doctype tag <!DOCTYPE html> for HTML emails. Older Rails 2 guide examples use Transitional doctype. As far as I know, HTML emails must use the most basic, old-style HTML code with some deprecated tags, so various email clients display it properly. This sugges...

PG gem errors on attempting to make connection

I have installed Postgres 8.4.4 via MacPorts per a RobbyOnRails installation guide. When I attempt to connect to a project I get the following error: establish_connection':RuntimeError: Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (dlopen(/Library/Ruby/Gems/1.8/gems/pg-0.9.0/lib/pg_ext.bundle, 9)...

Ruby on Rails and Cocoa

Hey guys, I am building an application in Cocoa that uses a local Ruby on Rails web server to communicate data and info between the client and server. There are times in the program where I need to poll the web server for some information using HTTP GET requests, but I'm not sure if that is the best approach. Are there any alternatives ...

ActiveRecord find through has_one association child attribute

I have models like this: class Discussion < ActiveRecord::Base has_many :comments has_one :special_comment, :class_name => "Comment" end class Comment < ActiveRecord::Base belongs_to :discussion # contains author end How can I select every Discussion through its adjoined :special_comment 'author' association. Effectively I w...

Dynamic method calling in a helper for Rails

I have a helper module with a bunch of method calls in the format def link_to_details_for_facebook(param1, param2) def link_to_details_for_twitter(param1, param2) def link_to_content_for_facebook(param1, param2) def link_to_content_for_twitter(param1, param2) is there a way to call one method such as, so I can dynami...

accepts_nested_attributes_for and Active Resource

I'd like to use accepts_nested_attributes_for with Active Resource. Is this possible? I have been experimenting in console and passing in nested attributes works, however the nested models fail to create because the foreign_key is never set. For example, I have a user class that accepts_nested_attributes_for :credentials. The JSON c...

Segfault on Mongrel_Rails start

When I run mongrel_rails start for my application, I get the following error: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/http11.bundle: [BUG] Segmentation fault ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin10] I am running Snow Leopard and Ruby, Rails, and PostgreSQL 8.4 v...