ruby-on-rails

Is it better to use routes or mod_rewrite to forward old URLs?

I recently changed some URLs in my Rails app and am curious if I'm better off using routes + controllers + redirect_to to forward the old URLs, or just use .htaccess with Apache's mod_rewrite? I'm using Apache + Passenger so htaccess files work, but was curious if there was a standard for this sort of thing. FWIW, the URLs were changed...

I need help with a Rails ActiveRecord Join - I know how to do it in SQL

I have 2 tables I need to join but the user_id column value is not the same in both tables. So I want to do something like this: In my controller 4 will be substituted with current_user.id select * from sites join pickups on sites.id = pickups.site_id where sites.user_id = '4' But using an ActiveRecord Find. Here are my association...

Using Ruby And Ubuntu With Optical Character Recognition

I am a university student and it's time to buy textbooks again. This quarter there are over 20 books I need for classes. Normally this wouldn't be such a big deal, as I would just copy and paste the ISBNs into Amazon. The ISBNs, however, are converted into an image on my school's book site. All I want to do is get the ISBNs into a string...

How could avoid the rspec drops the test database?

I have some fake data in the test database, but when I run rake spec the script drops and creates the whole database. How could I avoid that? or is it something I'm doing wrong? EDIT: I just don't want to generate 1.000.000 records from the database every time. It took so long. ...

How do I start Thinking Sphinx delayed delta rake task from deploy script?

Hi I have Thinking Sphinx setup and working however I am having a problem getting the Delayed Job rake tasks to start during deployment. I have the following task in deploy.rb which appears to execute, however the delayed jobs are not processed - they stack up until I run rake ts:dd from the server command line: namespace :thinkingsp...

URL Redirects for SEO (in Flash)?

I am creating a flash site and am trying to make it SEO. I'm thinking a possible solution would be to render html to any search engine bot, or to anyone who needs accessibility, and rendering the flash site for the rest of the users. First question is, is this acceptable for google, and SEO in general? This would mean I would redirect...

vimeo ruby gem auth_token example for oAuth?

Anyone know what the correct syntax to get an auth_token from Vimeo using the recently updated vimeo gem (http://github.com/matthooks/vimeo) using oAuth? I'm trying this: def authorize base = Vimeo::Advanced::Base.new(VIMEO_API_KEY, VIMEO_SECRET) redirect_to base.web_login_link("delete") end #end method --- get redirected to vime...

Adding Google Analytics to an app

I want to implement this new method of Google Analytics, I want to conditinally insert this code in the head section conditionally in production mode only, any suggestion to how to do this? http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html ...

Nested Attributes for Polymorphic Models

Hi, In my code, I have 4 models: Plan, Choice, Venue, CustomSuggestion, in order to allow users to create "plans" which consist of choices, which in turn consists of a suggested. My code looks something like this: class Plan < ActiveRecord : Base has_many :choices end class Choice < ActiveRecord : Base belongs_to :plan belongs_t...

including rake tasks in gems

1) Is there a 'best' place for rake tasks inside of gems? I've seen them in /tasks, /lib/tasks, and I've seen them written as *.rb and *.rake -- not sure which (if any) is 'correct' 2) How do I make them available to the app once the gem is configured in the environment? ...

One Table Or Three For Three Separate Objects That Have Identical Data Attributes?

I am building a site for a magazine that includes three different sections- articles, blog posts, and reviews. All three of these object types have the following columns in common: title, description, headline, subheadline, body, and author. Should I store them each in their own table, or should I just create one Posts table and add a ca...

rails routes params find for a form

Hello, I am having a bit of trouble with my rails application. It short, its a social networking app where users have a profile, have submissions, and can comment on submissions. My routes are as follows: map.connect '/:username', :controller => 'users', :action => 'show' map.connect '/:username/:id', :controller => 'submissions', :...

Repopulating page with previous values in rails

Hi. I have a validation that needs to be done in controller. If it fails I need to go back to the view action back again with all values populated as it is on the page. Is there a simple way to do that (using incoming params map). ...

How can I have two columns in one table point to the same column in another with ActiveRecord?

I run the risk of palm-to-forehead here, but I can't quite figure out how to do this with Rails' ActiveRecord sugar. I have a tickets table that has two columns (submitter_id and assignee_id) that should each reference a different user from the users table (specifically the id column in the users table). I'd like to be able to do things...

How to show the content of the form just entered in the ":confirm =>" option on Ruby on Rails

I am trying to have a way of confirming the information entered before actually saving it to the DB Considered making an individual confirmation page as discussed here http://stackoverflow.com/questions/445293/ruby-on-rails-confirmation-page-for-activerecord-object-creation However my form includes an attached file using paperclip wh...

Should native validations be tested in rails?

Everybody knows that automated testing is a good thing. Not everybody knows exacly what to test. My question is if native validations like validate_presence_of, validate_uniqueness_of and so on should be tested in the application. In my office we are three, one thinks it should be tested, one thinks it shouldn´t and I am up in the air...

Is using column limit options worth it?

Is there any point to specifying a limit option on string in migrations... class CreateAccounts < ActiveRecord::Migration def self.up create_table :accounts do |t| t.string :name, :limit => 64 end end end Should this be applied to all strings in the DB? What's the significance? ...

Showing status of current request by AJAX

Hi everyone, I'm trying to develop an application which modifies a couple of tasks of the famous Online-TODO List RememberTheMilk (rememberthemilk.com) using the REST API. Unfortunately the modifying takes a lot of time, so I want to give a feedback to the users. My idea was just to display a couple of text lines (e.g. modifying task 1...

HTTP Logging in rails?

Does anyone know of a plugin / gem that will log any HTTP requests your rails app may be making when responding to a request? For example if you are using HTTParty to hit an API, how can you see what outbound requests are coming out of your rails app? ...

How to get Regex to ignore URL strings

Hi, I have the following Regexp to create a hash of values by separating a string at a semicolon: Hash["photo:chase jarvis".scan(/(.*)\:(.*)/)] // {'photo' => 'chase jarvis'} But I also want to be able to have URL's in the string and recognize it so it maintains the URL part in the value side of the hash i.e: Hash["photo:http://www...