ruby-on-rails

Rails record versioning solution

I'm looking for a solution to version database changes in rails. Looking for something very basic. I mean like a wiki or SO edit versioning. ...

Amazon S3 Gem for Rails 2.3?

Which Amazon s3 gem is compatible with Rails 2.3 ? It needs to be compatible with the Paperclip gem too. ...

getc is obsolete; use STDIN.getc instead

When running rake gems:install I see this message: /opt/local/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:232: warning: getc is obsolete; use STDIN.getc instead How do I resolve the issue? ...

Ruby on Rails: What to do when two models share a lot of similar validations/validation_methods

I have a couple of models that are both "password" centric models. They don't belong in a single inheritance table and need to be tracked in separate tables. Logically they are both completely different types of models, but both have password and password confirmation tracking. They also use the same business logic for the password rules...

named_scope conditions and timezone mismatch

Here is the setup: end_date = DateTime.parse('2010-01-01 12:00:00-04') and sometimes it's initialized: end_date = 1.days.ago The question... do these named_scope(s) generate the same EXACT SQL? named_scope :before, lambda { |end_date| { :conditions => ["overdraft_transaction_payments.created_at < ?", end_date] }...

diffrence between mongrel and mongrel cluster ?

can Anybody brief expain to diffrence between mongrel and mongrel cluster ? ...

Rails - caching and permission based views

Hello, I use CanCan to check user permissions and display or suppress page content conditionally for my users. I want to cache my pages though, and even with fragment caching can't find an elegant solution... for example: cache do # much code if can? # little code else # little code # much code if can? # little cod...

Paperclip and Amazon S3 URL is too long

When the an image is stored to Amazon S3 using Paperclip the url of the image is too long: e.g. http://s3.amazonaws.com/railsapp/Users/am/Desktop/railsapp/public/system/avatars/1/thumb/16110022.jpg?1171724004 (this is basically http://s3.amazonaws.com/[bucketname]/[path on mac to image]) This is in my user model: has_attached_file :...

RoR: Custom update for record

questions --------- id topic_id created_by created_at question_text closed_by closed_at response_text It appears in a nested table under the topics table. I can easily create a question, I just have to exclude :created_by, created_at, closed_by, closed_at, response_text from config.create.columns. (created_at and created_by is filled ...

Join on polymorphic association

Hi guys I know that this is really bad idea but I want join three tables for my query on polymorphic association for example class Article has_many :comments, :as=>:commentable end class Post has_many :comments, :as=>:commentable end class Comment belongs_to :commentable, :polymorphic=>:true end and I need to get something s...

upgraded to rails 3, and now autospec in my rails 2 projects just exits

I've been working on a rails 2.3.8 app for a long time now. Autospec has been working like a champ. Last night, I started a new app in rails 3 and after some shenanigans got autospec working for rails 3. Now, in my rails 2 apps, when I run autospec, I get a single line of output and then it exits. loading autotest/rails_rspec I've b...

Ruby + JSON + Regexp

I'm working on a RoR project and I am passing a JSON object to a script. Specifically, a list of events to a jquery calendar. First I get the necessary events from active record and convert them to json: @events = CalendarEvent.find(:all, :conditions => ["mentor_id = ?", current_user]).to_json(:only => [:id, :availability, :starts_at,...

eager loading a small subset of all has_many objects based on conditions

How do I eager-load only some of the objects in a has_many relationship? Basically, I have four objects: Assignment, Problem, AssignmentUser, and ProblemUser. #assignment.rb has_many :problems has_many :assignment_users #assignment_user.rb belongs_to :assignment belongs_to :user has_many :problem_users #problem.rb belongs_to :assig...

User Disconnection Detection (i.e. "Online Status") Daemon

Summary: is there a daemon that will do postbacks when a user connects/disconnects via TCP, or is it a good idea to write one? Details: There are a number of questions based around this already; but I believe that this is a different "twist" on it. We're writing a Ruby on Rails web application, and we would like to be able to tell if a...

Collection_Select Default Value Not Set

I am having a strange issue with a collection_select I am using in an edit profile view in my rails application. The database IS being updated with the correct value, however the default value is not being selected for the select box when the user goes to edit their profile. I can not get a :include_blank => true or a :prompt => true t...

simple file upload with starling and workling

I have a basic scaffolding that uploads image files with paperclip. I would like to put the upload into a background process. I created this file: class UploadWorker < Workling::Base def send_file(options) end end I am not sure how to set this up in the controller def create @image = current_user.images.build(params[:imag...

validates_presence_of and with templates ruby on rails

I'm trying to validate some ratio buttons making sure the user as selected one of them. I do this by using: validates_presence_of In addition, I have specific template that I use for the page's layout. Normally, without the template layout, The anything that is missing is highlighted automatcially by the validates_pressense_of helper...

How do I make get attr_accessor_with_default work with a collection?

I want to give one of my models an attribute accessor that defaults to an array of eight zeros. This is the first syntax I tried: attr_accessor_with_default:weekly_magnitude_list, [0,0,0,0,0,0,0,0] The above didn't do what I expected because all instances of the model end up sharing the same Array object. The blog (http://barelyenough...

A bug in rails? About model inherited.

My env: ruby-1.9.2-preview3; rails-3.0.0.beta3 class PostFather < ActiveRecord::Base def self.inherited(subclass) end end class Post < PostFather end In the console: > Post.new # => TypeError: can't dup NilClass > Post.all # => TypeError: can't dup NilClass > Post.scoped # => TypeError: can't dup NilClass You can try ...

ActiveRecord marshal dump/load has a different behavior on boolean [rails]

Step 1: [setup] a = Aritcle.new(:some_boolean => false) a.save write_to_memcache(a.id, Marshal.dump(a)) b = Marshal.load(read_from_memcache(a.id)) If I do: b.some_boolean = nil b.save the some_boolean is not written back to the DB. DB still remains false. But: a.some_boolean = nil a.save works perfectly. DB is set to NULL. A...