ruby-on-rails

Use with_options with the Rails form helper

I have form that has :prompt => "Select" on many inputs: f.select :country, :prompt => "Select" f.select :city, :prompt => "Select" ... Is there a way to wrap this using with_options and DRY it up? ...

Step through each recently created element in Rails?

I'm creating an admin tool for a project where I create an Event, then create multiple Speakers (on one page), then need to create multiple Talks for each Speaker. Rather than have all the Speakers listed on one page after creation, and then put multiple Talks against each Speaker (which looks crazy due to all the input boxes), I'd like...

Popular RUBY ON RAILS WebSites

Which are the most popular websites created using ruby on rails.Currently i am using twitter and scribd. Any other useful websites are there. ...

Working with Starling and multiple instances of Mongrel through Mongrel Cluster

Situation: In a typical cluster setup, I have a 5 instances of mongrel running behind Apache 2. In one of my initializer files, I schedule a cron task using Rufus::Scheduler which basically sends out a couple of emails. Problem: The task runs 5 times, once for each mongrel instance and each recipient ends up getting 5 mails (...

ActiveRecord and loading data from related tables

Hi! My model looks like this (example): class Bank < ActiveRecord::Base has_and_belongs_to_many :currencies # other stuff end When I want to get some bank from database i do: bank = Bank.first :joins => :some_table, :conditions => { #some conditions } Now, is there any way to explicitly retrieve cu...

Rails 2.3 select loses value when post fails validation

I have a simple form where I set the default value of a select list as follows f.select :post, (1..5).to_a, {:value => @author.posts } if validation fails on the create action this list is always reset to 1. In the create method after testing validation if I set @author.posts = 5 then it will set the list to 5. However it does n...

How do I make a Rails ActiveRecord dependent on an attribute?

I have created an ActiveRecord for a customer, and now they would like it so when it's destroyed, it is actually kept around for a manual rollback. What I would like to do is create a boolean attribute called 'active', and it defaults to 1. When a record is destroyed, the attribute is toggled to 0. I know I could change all my queries...

cannot create directory at db:migrate

I have repository at github for ruby on rails project. First time i did push from comp. under windows system with msysgit. Then cloned this project from another comp. under ubuntu, did some changes, commited and pushed to repository at github. Now when i try to pull or even clone this repository from my comp. with windwos it results in...

Making generic classes Rails-y

I have a simple class I want to include in my Rails app, but I want to still be able to access all the Rails niceness, e.g use the gems, helpers, routes etc etc as normal. How can I do this? Is it the right thing to do? ...

Is there any Kestrel gems out there?

i'm interested with kestrel http://github.com/robey/kestrel/tree/master, is there any rubygems or library for connecting kestrel with ruby/rails? thanks ...

POSTing File Attachments over HTTP via JSON API

I have a model called Book, which has_many :photos (file attachments handled by paperclip). I'm currently building a client which will communicate with my Rails app through JSON, using Paul Dix's Typhoeus gem, which uses libcurl. POSTing a new Book object was easy enough. To create a new book record with the title "Hello There" I could...

Rails using custom :joins string to get combined INNER and OUTER JOIN on 3 models

Hi - I am trying to join 3 models together while using :conditions , and have hit a snag. Basically, I'm trying to limit the returned Items to those with a specific zipcode (zipcode is a field of a Location, each Item can have many Locations), AND those WITHOUT a specific Tag.name, if the Tag was created by the User doing the search (...

Best implementation of a multi-model association in rails?

Alright, a Rails Noob here, :D It looks like has__many :through is the latest greatest way to handle many to many relationships, but I am trying to keep this simple. Hopefully one of you guru's out there have handled this situation before: Here is the basic model setup I have now: class User < ActiveRecord::Base has_and_belongs_to_...

how to use to_sentence for links?

some thing like this: John send a message to user1, user2, user3 and user4 this does not work @users.collect{ |u| link_to(u.name, user_path(u)) }.to_sentence ...

Using Rails models with accepts_nested_attributes_for

I'm writing a simple Rails model called Person that has_many :phone_numbers and I'm trying to save the phone numbers in a complex form without manually writing setter methods. accepts_nested_attributes_for should do what I want but I'm having trouble getting it to work. Here's the code I have so far: Migration class CreatePeople < Acti...

How to select where ID in Array Rails ActiveRecord without exception

When I have array of ids, like ids = [2,3,5] and I perform Comment.find(ids) everything works fine. But when there is id that doesn't exist, I get an exception. This occurs generaly when I get list of IDs that match some filter and than I do something like current_user.comments.find(ids) This time I may have a valid comment ID, ...

rails fckeditor abnormal behaviour in firefox

I'm using Scott Rutherford's fckeditor rails plugin 0.1.2 for my project. I attached it at the bottom of a page which requires scrolling. When I scrolled down and started to insert text into the editor, everything is fine across all 3 browsers (Firefox 3.5, Chrome & IE8). The problem is when I pressed on the ENTER key to insert a new pa...

How to use ruby to get string between html <cite> tags?

Greetings everyone: I would love to get some infomation from a huge collection of Google Search Result pages. The only thing I need is the urls inside a bunch of html tags. I cannot get a solution in any other proper way to handle this problem so now I am moving to ruby. This is so far what I have written: require 'net/http' require...

Snow Leopard + cucumber/webrat/rspec

Since I've upgraded to snow leopard I've been having tons of problems using cucumber to run my features. Currently, every time I run cucumber I get the following error. Missing these required gems: webrat cucumber >= 0.3.100 webrat >= 0.5.0 rspec >= 1.2.6 rspec-rails >= 1.2.6 You're running: ruby 1.9.1.243 at /...

Can i stop Rails from using a timestamp prefix for migrations after some migrations have been generated using timestamps?

There are about a hundred or so migrations in my migrate folder with numeric prefixes, then about a hundred or so with timestamp prefixes, so i guess at some point Rails version was updated. Now I want to go stop Rails from using timestamp prefixes as i prefer numeric prefixes. What is the best way to accomplish this, or is this even pos...