ruby-on-rails

Using mod_rails to host multiple apps under SSL, same domain

I'm trying to get multiple rails apps hosted under the same domain, but different directories. My configuration before attempting to host multiple apps (which works great), looks like this: <VirtualHost *:443> ServerName secure.mydomain.com DocumentRoot /root/store/public </VirtualHost> I google'd around and found documentati...

Replace umlaute (äüö) for SEO link in rails - best way

Hi, I'm using the permalink_fu plugin to create permalinks from titles. My problem is: If the title contains german characters, they are just replaced with '_'. What I need is something that replaces ä with ae ü with ue ö with oe I fount String.tr but the problem here is that it replaces 1 character with 1 replacement, so it would wor...

SEO urls in rails: .html ending vs. none. What's best?

Hi, I'm thinking about a good SEO Url strategy for a blog application. I'm not sure - and maybe it's just the same - but what is better? With or without .html /blog/entry_permalink_name.hml VS /blog/entry_permalink_name What do you think? ...

Searching and sorting by a float field with thinking sphinx

I'm using thinking sphinx to for search on a rails app. I have a float field called 'height'. I need to be able to search this field for exact values (i.e. exactly 6.0, not 6.5). I also need to be able to sort on the field. What I have so far: indexes height, :sortable => true Problem: doesn't sort properly, returns 6.0 and 6.5...

Quickest way to delete enormous MySQL table

I have an enormous MySQL (InnoDB) database with millions of rows in the sessions table that were created by an unrelated, malfunctioning crawler running on the same server as ours. Unfortunately, I have to fix the mess now. If I try to truncate table sessions; it seems to take an inordinately long time (upwards of 30 minutes). I don't c...

Why isn't Capistrano copying my files?

I am currently deploying a Rails application using Capistrano. Cap deploy:update_code usually works just fine to copy over application files from the SVN to the rails container, however when I do it now, it copies the folders but they are all empty. Any ideas of why this would happen or how to fix it? ...

Functional testing redirection in a Rails controller

I'm trying to make it so when a model is created via created action it redirects to its show action. That part works fine, but I can't get my functional test to behave. These tests have been modified from what the scaffold provides. def setup @thing = Factory(:thing) assert(@thing.id, "Virtual fixture not valid.") end def...

ActiveRecord models cached in rake tasks?

I know that in rails 2.3.2 ActiveRecord queries are cached, i.e. you may see something in the development/production log: CACHE (0.0ms) SELECT * FROM `users` WHERE `users`.`id` = 1 I was wondering if the same principles apply to rake tasks. I have a rake task that will query a lot of different models, and I want to know if I should...

Why is it not good to have a primary key on a join table?

I was watching a screencast where the author said it is not good to have a primary key on a join table but didn't explain why. The join table in the example had two columns defined in a Rails migration and the author added an index to each of the columns but no primary key. Why is it not good to have a primary key in this example? c...

In a Rails migration, is it possible to indicate that a newly added column should be before or after an existing column in the table?

Let's say I create a table in a Rails migration, specifying to omit the ID column: create_table :categories_posts, :id => false do |t| t.column :category_id, :integer, :null => false t.column :post_id, :integer, :null => false end Later I decide I want to add an ID column as a primary key so I create a new migration: class Change...

In a join table, what's the best workaround for Rails' absence of a composite key?

create_table :categories_posts, :id => false do |t| t.column :category_id, :integer, :null => false t.column :post_id, :integer, :null => false end I have a join table (as above) with columns that refer to a corresponding categories table and a posts table. I wanted to enforce a unique constraint on the composite key category_id, p...

Rails application settings

I'm creating two related Rails applications, and I'm noticing a lot of non-DRY work. For example, the @title field being set in the various controller methods do the same thing, except for the application title, as in: # SiteController (application 'Abc') def SiteController < ApplicationController def index @title = 'Abc' end ...

How to access named_scope arguments from named scope extension?

Hi, following example: named_scope :search, lambda {|my_args| {...}} do def access_my_args p "#{my_args}" end end # Call: Model.search(args).access_my_args As you can see I want to access the arguments from the lambda in the named_scope extension. Is there a way to do this? A more specific example: class User < ActiveRecor...

Generating Missing Spec Files for RSpec

Is there any command available for generating all missing spec files for existing models / controllers? I have a project that has several models that have been generated with out spec files. ...

set configuration constants depending on environment in rails

I would like to define a constant (like the admin-email-adress) depending on the environment. What is the easiest way to do this? I'd like something like that, in development.rb (or test or production.rb): ADMIN_EMAIL = "[email protected]" And be able to access it by calling something like ADMIN_EMAIL Is there an easy way or do I have t...

access domain user thru adam

Hi I'm using redmine (a rails ticket management) and I'd like users to be able to log with their net user and password. I've followed the ADAM Step by Step Guide from Microsoft and setup an ADAM instance on my local machine. http://www.microsoft.com/downloads/details.aspx?familyid=5163B97A-7DF3-4B41-954E-0F7C04893E83&amp;displaylang=e...

ActiveRecord field normalization

I feel bad asking this question, as I thought I knew enough about Activerecord to answer this myslef. But such is the way of having SO available ... I'm trying to remove the commas from a field in a model of mine, I want the user to be able to type a number , ie 10,000 and that number be stored in the database as 10000. I was hoping th...

Question about loading data in a Rails migration

I created number of migrations starting with a definition for a Posts table. class CreatePosts < ActiveRecord::Migration def self.up create_table :posts do |t| t.column "title", :string, :limit => 100, :default => "", :null => false t.column "content", :text, :null => false t.column "author", :string, :limit =>...

should script/plugin create a .git folder?

I noticed that if I do something like: script/plugin install git://github.com/plug-xyz.git It says it is creating a .git folder: Initialized empty Git repository in /Users/g/Documents/app/vendor/plugins/xyz/.git/ But after the plugin is installed, it seems that the .git folder is gone. I ask because when I try to update the plugin...

rake db:schema:dump doesn't provide data migration info - is there an automated way to get this?

rake db:schema:dump This command gives you the schema of a legacy database and you can build a migration for that database off the generated schema. But if that database had data in it, it would be nice if there was a rake command to retrieve the data in a migration file generated by Rails. Perhaps I'm dreaming - it's probably aski...