ruby-on-rails

Multiple conditions with will_paginate

I am using will_paginate for pagination but I can't seem to use more than one condition at a time. For example, if I want to have a sql query that ends in "Where office_id = 5", then it's pretty straight forward, I can do that. but what if I want to do "Where office_id = 5 AND primary_first = 'Mark'"? I can't do that. I have no idea...

Can I share a cookie between multiple domains pointing to the same Rails app?

I have x.com pointing to apple.y.com, and separately, also one.y.com and two.y.com. I want the user who visits either x.com, one.y.com or two.y.com to share the same sessions. Is this possible? If not, what's the best compromise? ...

How do I configure Apache to handle missing image assets?

All the image assets in my Rails application live in /public/images and are served by Apache if they exist on the server. If a request for a missing image is made, Apache can't serve it so it gets passed on to Rails which subsequently raises a 404. Ideally I would like any request for a missing image to be handled at the Apache level, ...

Ruby: Alter class static method in a code block

Given the Thread class with it current method. Now inside a test, I want to do this: def test_alter_current_thread Thread.current = a_stubbed_method # do something that involve the work of Thread.current Thread.current = default_thread_current end Basically, I want to alter the method of a class inside a test method and recover ...

With Ruby, does "gem install" use "--include-dependencies"... just the doc is a little outdated?

Using Ruby on Rails, if I do a gem help install a part of it says: -y, --include-dependencies Unconditionally install the required dependent gems [...] Defaults: --both --version '>= 0' --rdoc --ri --no-force --no-test --install-dir c:/ruby/lib/ruby/gems/1.8 but if I do a gem install -...

Rails "rake test" crashing

Hi, this might be rather unspecific, but I'm trying to do 'rake test' on a new rails app, and end up with (in /Users/myname/dev/railstest/RailsApplication1) /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:test" "/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" /System/Library/Frameworks/...

Upgraded activerecord-sqlserver-adapter from 2.2.22 to 2.3.8 and now getting an ODBC error

I have been using MSSQL 2005 with Rails for quite a while now, and decided to bump my gems up on one of my projects and ran into a problem. I moved from 2.2.22 to 2.3.8 (latest as of writing) and all of a sudden I got this: ODBC::Error: S1090 (0) [unixODBC][Driver Manager]Invalid string or buffer length I'm using a DSN connection wit...

Separate validation file for each model in rails.

I have a too many models and want to maitain separate validation and relationship files for each model in rails. Is there any way i can maintain it with rails? Any specific advantage to do it? ...

Ruby on rails user authentication using linux passwd file?

Hi, Is there an authentication plugin for rails which uses the host system's /etc/passwd file to provide user/password information? The goal is to provide user login to a rails app for the same users who already have local login accounts to the linux machine hosting the rails app. Cheers. ...

Rails Custom Plugin/Gem with Partials

I am writing a gem which provides helpers for views. The HTML I want to insert via the helper is complex enough that I'd rather write it in a _partial.html.erb file. How do I get the gem's view path include in the application's load_path? Note: the only gem I've found that does something like this is Devise. When a view cannot be found,...

Clearance with Test::Unit

I am using Clearance for authentication with my rails app which works. But now all my unit tests fail because they redirect to the sign in page, which makes sense. Clearance seems to have helper functions for fixing that but I can only find them for Shoulda. Are there equivalent helpers for Test::Unit? ...

Use Delayed::Job to manage multiple job queues

I want to use Delayed::Job (or perhaps a more appropriate job queue to my problem) to dispatch jobs to multiple background daemons. I have several background daemons that carry out different responsibilities. Each one is interested in different jobs in the queue from the Rails app. Is this possible using Delayed::Job, or perhaps there i...

Rails Updating Nested Model Collection Select

I have a contrived nested Rails form like the following <% form_for @a do |fa| %> <% fa.fields_for :b do |fb| %> <% fb.fields_for :c do |fc| %> <%= fc.label :option_id %> <%= fc.collection_select :option_id, ModelD.all(:select => "id, name"), :id, :name %> <% end %> <% end %> <% end %> and then ...

How to add an image field into a Rails app?

I'm building a rails app that has an image upload field. I don't have any idea how to handle images in Rails. (The uploaded image would also require some processing as well.) Can anyone tell me how I can go about doing this? thanks. ...

Dynamically adding a class to a div in a .erb with Ruby on Rails

I have this div <div class='notice'> And I want the result to be <div class="notice error"> And Is there a way to add a class in my erb? I tried <div class="notice #{new_class}"> But that doesn't escape into ruby code when it renders... and ideas? ...

How to efficiently implement a blocking call with Rails, while letting the client wait for the reply.

We have a web service written in Rails. The API is published and we cannot change it. Our app communicates with a remote web service that sometimes hangs or takes several seconds to reply. Client -> Our Web Service -> Remote Web Service Currently, if the remote web service hangs for 5 seconds, one of our rails processes on our web s...

How to make optgroup label selectable in Rails form? Urgent

Hi, I have created the following select using the option_groups_from_collection_for_select form helper in Rails as part of a search feature. All Categories Garden Accessories Gardens Random Sheds Playsets The problem is, I want a user to be able to search all of the "Garden" sub-categories at once, but as "...

How to completely uninstall rails 3.0.0.beta3 and all its dependencies?

If I do sudo gem uninstall rails -v 3.0.0.beta3, it uninstalls rails but leaves the beta3 versions of activerecord, actionmailer, etc. How do I completely uninstall rails 3.0.0.beta3 and all its dependencies automatically? I would like a clean slate for the RC and final releases. ...

Chaining Named Scopes not working as intended

I have 2 simple named scopes defined as such: class Numbers < ActiveRecord::Base named_scope :even, :conditions => {:title => ['2','4','6']} named_scope :odd, :conditions => {:title => ['1','3','5']} end if I call Numbers.even I get back 2,4,6 which is correct if I call Numbers.odd I get back 1,3,5 which is correct When I chain t...

has_many in rails

I have a 'users' table which stores all of my websites users, some of which are technicians. The users table has a 'first_name' and 'last_name' field as well as other fields. The other table is called 'service_tickets' which has a foreign key from users called technician_id. This gives me a real problem because when I am looking at t...