ruby-on-rails

Does writing has_many extensions for ActiveRecord requery the database?

If I have something like this: class Post < ActiveRecord::Base has_many :comments, :as => :commentable do def approved find(:all, :conditions => {:approved => true}) end end end class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true end ...when I do this, I get 2 hits to the database (not...

Can't get autotest running with Rails 3

Not sure what's going on, but I can't get autotest to work with rails 3. I'm using ruby 1.9.2-head and Rails 3.0.0 and I have all of the relevant gems installed. I'm declaring them in my gemfile like this: group :development do gem 'rspec-rails', '2.0.0.beta.18' gem 'annotate-models', '1.0.4' gem 'autotest' gem 'autotest-rails'...

typing bin/jruby -S rails myapp I get the output telling me how to use the rails command?

I insalled jruby, and when I type: > bin/jruby -S rails myapp I get: bin/jruby -S rails myapp -d mysql Usage: rails new APP_PATH [options] Options: -r, [--ruby=PATH] # Path to the Ruby binary of your choice # Default: /Users/snad/dev/jruby/jruby-1.5.2/bin/jruby -d, [--database=DATABASE]...

css stretching the 2 column grail to meet a footer

Hello, I am sure this is a common frustration - but I am trying to just do a two column liquid with a footer in rails. The problem that I am having is that I can get the footer to stick on the bottom, or to the columns. I am using this for my basis for the columns, I just need them to stretch to the bottom of the page, filling with ...

Ruby on Rails -- How can I update ruby to >= 1.8.7

Hello, I've been trying to figure this out but its starting to make me want to pull my hair out. I'm installing RoR on a new machince using instantrails. Whenever I run "gem update --system", I get the error for several gems? that "activesupport requires Ruby version >= 1.8.7" I run "ruby -v" and it returns "ruby 1.8.6 (2007-09-24 pat...

2 domains using the same host, but routed differently

Hi folks, i have 2 domains (a.com and b.com) using the same application. However, I would need them to point to different routes. a.com should use the action: /home/a_index b.com should use the action: /home/b_index What is the right way to handle this in rails? ...

Can't find Magick-config

I am getting the following error when I try to run my dev console (MAC OS X / Snow Leopard). Does anyone know the solution? /usr/local/bin/ruby extconf.rb checking for Ruby version >= 1.8.5... yes checking for gcc... yes checking for Magick-config... no Can't install RMagick 2.13.1. Can't find Magick-config in .:/usr/local/bin:/usr/loc...

undefined method `each' in a factory_girl / rspec2 scenario

I'm trying to Factory a Post associated with a Vote. So that Post.votes would generate the Vote's that are associated with it. Factory.define :voted_post, :parent => :post, :class => Post do |p| p.association :votes, :factory => :vote end And my rspec2 is relatively straightforward : describe "vote scores" do it "should show me t...

Infamous 'byte sequence" error with local install of gitorious on Ruby 1.9.1

I am trying to install gitorious on my personal server but I am not very familiar with Ruby or the frameworks and scripts involved in getting to the finish line. I am following the following instructions to install gitorious on my CentOS 5.4 server: http://www.tikalk.com/alm/blog/installing-gitorious-centos-55 The site comes up but a...

In Ruby on Rails, what is a good way to get subclass's name in a base controller class?

If both ProductsController and CategoriesController both inherit from GenericController, what is a good way to get the string products in the base class when the URL is pointing to the Products controller? (in this case, the base class's index action is doing things that would need to use the string products to query the database) self...

In Ruby on Rails, cannot render :controller => 'generic', :action => 'top_pages' but need to use :template => 'generic/top_pages'?

it seems that the :controller option doesn't do anything? Won't specifying the whole path be a little bit lower level than specifying using :controller? ...

Ruby on Rails 3 Params Hash Question

Let's say we are passing in something like :mash => true Now inside of params I want to takeit = params[:mash] What class is takeit? It's not boolean of course. Thanks for helping. ...

Rails 3's link_to('&raquo;', url) won't work if it is &raquo; or other entities

because it will not show up as » but will show up as &raquo. Is there a way to show it? ...

Why am I getting a 500 error but cannot understand why because the route and controller exists in rails

Here is my route: map.skip_contact_postalcard 'contacts/:contact_id/postalcards/:postalcard_id/skip', :controller => 'contact_postalcards', :action => 'skip' Here is my controller for ContactPostalcardsController: def skip @contact_postalcard = ContactPostalcard.new(params[:contact_postalcard]) @con...

How do I add a WHERE statement to this :select in rails?

I have the current find statement with :select: @list = Contact.find :all, :select => "companies.name AS co_name, COUNT(contact_emails.id) AS email_count, COUNT(contact_calls.id) AS call_count, COUNT(contact_letters.id) AS letter_count, COUNT(contact_postalcards.id) AS posta...

How to select records where a child does not exist

In rails I have 2 tables: bans(ban_id, admin_id) ban_reasons(ban_reason_id, ban_id, reason_id) I want to find all the bans for a certain admin where there is no record in the ban_reasons table. How can I do this in Rails without looping through all the ban records and filtering out all the ones with ban.ban_reasons.nil? I want to do t...

Ruby on rails "No route matches"

Hi all, I am new to Rails and am just implementing some basic applications. Just starting on my second app and have run into what is a basic problem, but Google is yielding me nothing. Getting this error: No route matches {:controller=>"user", :action=>"admin_login"} Here is my routes.rb Blah::Application.routes.draw do r...

How do I interpret this delayed_job error on heroku?

I am trying to run delayed_job on heroku and it doesn't appear to be working. So I went into the heroku console to check out what might be going on with the following: Delayed::Job.find(:last) This is what I came back with: => #<Delayed::Job id: 241, priority: 0, attempts: 22, handler: "--- !ruby/struct :SomeMailJob \ncontact: !ruby...

Handling JSON in JS/ERB template in Rails 3

I have no trouble making typical AJAX calls to and from Rails(3) with JSON objects and jQuery-rails (jQuery library plus a special rails.js file). In one controller, though, I want to RETURN some JSON in an erb template (create.js.erb) after an AJAX call. I've tried every combination of things in the controller (@object.to_json, '[{"co...

Can I get the name of the current controller in the view?

I am rather certain this is a stupid question, but I can't find the answer. Is there a way to figure out what the current controller is from within the view? For an example of why I would want to know this: if several controllers share the same layout, I may have a part in the layout ERB file where I want to highlight the current page'...