ruby-on-rails

How can I get validation "ifs" to use parameters (Ruby on Rails)

For conditional validation in Rails, I can do this: mailed_or_faxed_agenda = Proc.new { |me| me[:agenda_mailed_faxed] } validates_presence_of :agenda, :if=>!mailed_or_faxed_agenda but I don't know how to parameterize the Proc. I would love to use if=>blah(name) but I cannot figure out how to it. Any ideas? Note: In these ifs one can ...

To use Model as Resource or not?

So I have a User, Post, and Vote models. User has_many Vote Post has_many Vote In my unit tests I was defining a method called @post.vote_up which creates a vote for a post, but then I started thinking whether or not such an interface would allow for restful methodology. If I were to call /topic/1/votes with a POST, the VoteControl...

How do I re-use named scopes?

Hi I have a named_scope in my User model as following. named_scope :by_gender, lamdba { |gender| { :conditions => { :gender => gender } } } I want to create other two named scopes which re use this one something like, named_scope :male, lambda { by_gender('male') } named_scope :female, lambda { by_gender('female') } Any idea what...

Simple Question: Is Rails 2.3.4 backward compatible with Rails 2.3.2?

A client is indicating that the Rails version I have installed on my Ubuntu servers (2.3.4) is not backward-compatible with the older Version 2.3.2. I want to know if that is true or not before I attempt to install the older Rails. ...

What's the best practice to set up an edit view in which you match something with other things coming from very large collections?

I have a design question. Hope this doesn't come across as a lazy attempt. I'm writing a simple accounting application: A ledger has many accounts, each account has many transactions, and so on. Double-entry accounting dictates we match transactions with other transactions, so I have a separate model called LedgerItemGroup, which has m...

Rails error with validation and multiple models, can't convert HashWithIndifferentAccess into String

Hey rails folks, I haven't used rails since version 1.2 or so and a few things have changed. I have an issue where I am trying to save an empty model to get validation errors on attributes using :validates_presence_of and instead I am getting the error 'can't convert HashWithIndifferentAccess into String'. I will attempt to simplify my ...

Heroku: Serving Large Dynamically-Generated Assets Without a Local Filesystem

I have a question about hosting large dynamically-generated assets and Heroku. My app will offer bulk download of a subset of its underlying data, which will consist of a large file (>100 MB) generated once every 24 hours. If I were running on a server, I'd just write the file into the public directory. But as I understand it, this is ...

Is it worth using "pretty URLs" if you don't care about SEO/SEM

I'm designing a hosted software-as-a-service application that's like a highly specialized version of 37Signal's Highrise product. In that context, where SEO is a non-issue, is it worth implementing "pretty URLs" instead of going with numeric IDs (e.g. customers/john-smith instead of customers/1234)? I notice that a lot of web applicati...

Treacherous ActiveRecord behavior?

I have a Post class with a vote method which creates a Vote instance This doesn't work def vote(options) vote = self.votes.create(options) return vote if vote.valid? nil end This does work def vote(options) options[:post] = self vote = self.votes.create(options) return vote if vote.valid? nil end Shouldn't the...

Disabled/Custom params_parser per action

Hi, I have a create action that handles XML requests. Rather than using the built in params hash, I use Nokogiri to validate the XML against an XML schema. If this validation passes, the raw XML is stored for later processing. As far as I understand, the XML is parsed twice: First the Rails creates the params hash, then the Nokogiri pa...

Set content-disposition on public file types in Rails?

I have some PDF files in a public rails folder. I want to set the response header "content-disposition" to "attachment". I know I can create a controller to read the files and set the header myself, but is there some general application wide setting that i can enable/configure? Thanks in advance. -JP ...

Ruby 1.9.1-p234, Passenger 2.2.5, Rails 2.3-stable closed stream on POST request

I've setup Ruby 1.9.1 (p234) on a Ubuntu server. I'm trying to deploy a Rails app which vendors Rails 2.3-stable on Apache 2.2/Passenger 2.2.5. GET requests work fine, POST requests break immediately with the following log entry: Processing UsersController#new (for 80.203.77.44 at 2009-10-24 20:54:55) [GET] Parameters: {"controller"=...

Helper method or Model or Controller?

Say I have a form_for with a select menu to assign a User on a belongs_to association: ... form.select :user_id, @users, :prompt => "Select a User" ... Currently I have @users in the controller as follows: @users = User.all.map { |u| [u.full_name, u.id] } I feel like this logic should maybe moved into a helper or even to the model....

Is ActiveSupport::CoreExtensions::String::Inflections.constantize safe to use with user-supplied data?

Background Currently, I am working on a Rails application. I have different products that can be processed through different vendors. All vendors require a text file in a particular format in order to process the orders. I decided to use a Factory class to generate instances of the Formatter classes that will render the order informati...

How to create integration test for file upload in Rails?

What is the best way for testing file uploads for Rails Applications? I'm currently using Paperclip for uploads, but I guess that doesn't make much difference. Should I even create tests for file upload, or is it better to just stub it all out and don't create any real upload tests? Say I have some tests just for the upload. Should I a...

Count and Select Object in ActiveRecord with 1 query

We have objects that we want to represent in stacks (think of stacking items in an MMO). There will be duplicate rows. Let's say our owned_objects table looks like this. user_id | object_id 1 | 27 1 | 27 3 | 46 3 | 46 5 | 59 I want the query to do SELECT user_id, object_id, count(*) AS count FROM ...

How do I setup my Rails Apps to Run through Phusion Passenger?

Hello folks, I have the following doubt: I have an application in Rails+MySQL and I want to run this with Apache + Passenger, I have both installed, but when I run ./script/server my app starts running with WebRick, how do I change it for work with Passenger and Apache? P.S: I'm on Ubuntu 9.04 Jaunty Jackalope, please consider the fact...

using paperclip to get list of style/geometry pairs, even without valid object

I am working on maintaing an old code base and I'm migrating attachment_fu to paperclip. I migrated one thing but now I'm having a small issue. There's a partial that renders images given the type of image and a thumbnail style. I fixed the part to render the image and that's fine, but the "else" assumes that there actually is no photo ...

Rails - Accessing Another Database?

I've set up a Rails app using MySQL, with the database 'DatabaseA'. My Rails app is a port of a PHP app that I've written earlier, so there's some data in the PHP app's database (DatabaseB) that I'd like to port over. It's not as simple as an export/import. I've made some schema changes to the database which would require me to manipulat...

How do I check the Database type in a Rails Migration?

I have the following migration and I want to be able to check if the current database related to the environment is a mysql database. If it's mysql then I want to execute the SQL that is specific to the database. How do I go about this? class AddUsersFb < ActiveRecord::Migration def self.up add_column :users, :fb_user_id, :int...