ruby-on-rails

mapping to value in deep hash

Hi all, I'm doing an application using mongodb and mongoid and I'm facing a problem where I need to map something in one document to something in another document. My plan is to store something in a document that I can then use to figure out what value for it to fetch from a different collection. But, this is more generally a ruby quest...

Proxy Objects with ActiveRecord models - method_missing not working sometimes

Hello all! I've been using a model of my application as a proxy to other objects that define behavior. class Box < ActiveRecord::Base belongs_to :box_behavior, :polymorphic => true, :validate => true, :foreign_key => 'box_behavior_id', :dependent => :destroy [...] def initialize(opts = {}) super(opts) self.box_behavi...

How to cache tags with acts_as_taggable_on?

Hello, guys! I have model with tag context: class Product < ActiveRecord::Base acts_as_taggable_on :categories end I'm trying to initialize tags caching: class AddCachedCategoryListToProducts < ActiveRecord::Migration def self.up add_column :products, :cached_category_list, :string Product.reset_column_information ...

Handling Net::HTTP.get failures

The following line: page_source = Net::HTTP.get(URI.parse("http://not-a-real-url.com")) When passed a url that is properly formatted, but doesn't go anywhere (like the example above), dies out with: getaddrinfo: nodename nor servname provided, or not known I'm trying to figure out how to "begin / rescue" this condition, but I can't...

Routing / in Rails

I'm writing a simple Rails app with one main controller and I want to map /(:action(:id)) to this controller (basically remove the controller prefix at the beginning), but still have the path helpers I get by using map.resources. I tried map.root :controller => 'notes', but I get an error: undefined method `note_path' for #<ActionV...

Capturing stdout in real time in rails

I'm firing off cap tasks and other command line scripts from a function but I'm wondering what the best way for me to display real time logs for it. ...

unnecessary debug info in rails view

In my rails app I'm displaying some posts using nested loops. In development mode, after each loop completes the post objects are dumped in plain text in sequence. So it looks like this: It's unnecessary and kind of obnoxious. What causes this behavior and how do disable it? Edit: here is the loop: = @posts.each do |post| .post %...

How do I install / use Devise in Rails 2.3.5?

I have tried to install from the v.1.2.oauth branch of Devise on Github, but I still get an error. How do I install the devise gem on a rails 2.3.5 application? In particular, I want the one that works with omniauth gem install devise -v "1.2" ERROR: Could not find a valid gem 'devise' (= 1.2) in any repository config.gem 'devise'...

trying to run rails_upgrade plugin and getting a fork() error:

I am investigating whether I should upgrade from rails 2.3.5 to rails 3, so installed the upgrade plugin and ran it: rake rails:upgrade:check Got an error: ** Invoke rails:upgrade:check (first_time) ** Execute rails:upgrade:check rake aborted! fork() function is unimplemented on this machine ...

How do I link to an external stylesheet in Ruby on Rails?

I'm trying to link to the YUI reset stylesheet in my RoR layout using the following statement... <%= stylesheet_path("http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css") %> but this path is being echoed on my page instead of being applied. I got this syntax from the the rails docs. What am I doing wrong? Thanks! ...

Rails 3 - Using LIKE to search a combined 2 columns...

Hello, I'm following ryan's Simple Search Form tutorial here: http://railscasts.com/episodes/37-simple-search-form I have the following line in my Users Model: find(:all, :conditions => ['fname LIKE ?', "%#{search}%"]) But what I'd like to do is search across a combine 2 columns,: fname & lname As users are searching my full names:...

Rails 3 - Help me setup an AJAX Search Form

Could use some help setting up an AJAX Search form for Users... config.rb - controller: resources :users, :only => [:index, :show, :searchresult] do collection do get 'searchresult' end end Model def self.search(search) if search find(:all, :conditions => ['name LIKE ?', "%#{search}%"]) else find(:all...

rails performance test is failing

Simple performance test, I have installed ruby-prof and no other gems are missing, rake test:profile returns the following error. the test is simply. require 'test_helper' require 'performance_test_help' # Profiling results for each test method are written to tmp/performance. class BrowsingTest < ActionController::PerformanceTest ...

Rails Users has_one :profile vs. show page

Hello, I have a best practice/efficiency/performance issue. If I want to have a profile page for each user in my system and i already have a user model. Is it better to have all the users information in the user model and pull it on the show page of users so users/show will access the user model and grab all the relevant data like a...

Rails -v says I'm running 3.0, but I need to run 2.1.1 to get this app installed

I tried to do: rake db:migrate to get this app from github installed on my mac, and I got this error: Missing the Rails 2.1.1 gem. Please `gem install -v=2.1.1 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version i...

How do i skip activation in rails?

I am using the restful authentication plugin in rails and i need to skip the authorization and log the user in immediately...How can this be done Any ideas would be highly appreciated ...

importing fixture data from mysql

Is there anyway to import data using mysqldump rather than fixtures during a test (rake test:profile in this case). I have not been successful in exporting mysql data in yml format (which works ok) and importing it into rails (doesn't work, rake task complains about formatting of the yml file whose integrity seems intact). What are som...

Guidance in setting up some RVM environments

So I want to create environments for rails 3 and rails 2.1.1 How do I do this? Where do I look for the various versions of rails? I get an error when I try: rvm 1.9.2-head ruby ruby-1.9.2-head is not installed. I just followed what I read on: http://rvm.beginrescueend.com/gemsets/creating/ ...

Do I really need the @rails3 when creating a gemset?

I'm confused, what does the @rails3 do when creating a new gemset? I want to run both rails2.1.1 and rails3 applications, and switch between the two. I create a rvm for 1.9.2 and 1.8.7 And inside 1.9.2 I created 2 gemsets, and installed rails 2.1.1 in one gemset, and rails3 in another gemset. Am I doing this right? I'm reading othe...

help installing this Ruby app from github

http://github.com/bestbuyremix/BBYIDX I manually installed all the gem's required that where in the .gem file, for some reason bundle install didn't work (guess b/c no GEMFILE ?) I am using rvm, so I have rails 2.1.1 running also. when I go into the main folder for the application, and run: rake db:migrate --trace I get this error:...