ruby-on-rails

Caching friendly_id plugin

Class Product < ActiveRecord::Base has_friendly_id :name, :use_slug => true end What is the most efficient method to store the slugs within the 'products' table. I have complex find queries, and the joins with the 'slugs' table give me performance bottlenecks. ...

How to do join with SUM in ActiveRecord

Let's say I have two simple models project t.string :title vote t.references :project t.integer :value When I do loop throuh all projects, I also want to include sum of all votes, because doing projects = Project.all foreach project in projects sum = project.votes.sum(:value) ... isn't really effective. Is there...

Display first record in rails

Assuming I have a comments model and a posts model, What code can I use in a view to display the first comment of the post being linked? ...

How do I get webrat / selenium to "wait for" the CSS of the page to load?

When I use webrat in selenium mode, visit returns quickly, as expected. No prob. I am trying to assert that my styles get applied correctly (by looking at background images on different elements). I am able to get this information via JS, but it seems like the stylesheets have not loaded and/or gotten applied during my test. I see that...

awesome nested set order by

Hey guys, Im using the awesome nested set plugin for ruby on rails. How do I go about sorting by likea :name column or something ? Currently shows the tree like A -C -B I want it like A -B -C ...

Polymorphic Routes in Rails - in views

Hey guys, I have comments as a polymorphic model its attached to posts, reviews, etc. I also have an action in comments, called test for example I have my routes setup, so test_post_comment_path works (to call the test action in the comments controller) the problem is, in my partial view, I want that route to be able to change, bas...

Best way to implement "history of edits" in Rails?

I want users to be able to see what was added / changed in a blog post. I'm using Vestal Versions (great gem) to keep track of changes, but I don't know how to show this to users so they can see what has changed. My first impulse is to find a diffing library for ruby and just show the diff between version N and version N-1. What's a goo...

cruisecontrol.rb

we are using cruisecontrol.rb for CI. but cruise control is failing with this output /opt/ruby-enterprise-1.8.6-20090610/lib/ruby/site_ruby/1.8/rubygems.rb:258:in `activate': can't activate activesupport (= 1.4.2, runtime) for [], already activated activesupport-2.2.2 for ["rails-2.2.2"] (Gem::Exception) from /opt/ruby-enterprise-...

Only one instance of a Model in Rails

I'm working on my first Rails app. It needs to store some information about a single advertisement that will appear on every page. The admin just needs to be able to set the URL, Title, and an image. Obviously, I only need one instance of this ad object. I created a model that inherits from ActiveRecod::Base, but that seems like the wro...

Workling logs in production

Anyone now why I can't see logs for workling in workling.output or production.log? In development the logs show up in the development.log. In my environments/production.rb I have the log levl set to debug. config.log_level = :debug I'm starting Starling and Workling like this server > /usr/bin/starling -d -P /tmp/pids/starling.pid -L...

Show pending migrations in rails

Is there a rake task that shows the pending migrations in a rails app? ...

Difference between form_for , form_tag?

What is the difference between form_for and form_tag? Is anything different for form_remote_for and form_remote_tag? ...

How to resolve deprecation warnings for OpenSSL::Cipher::Cipher#encrypt

I've just upgraded my Mac to Snow Leopard and got my Rails environment up and running. The only difference -- OSX aside -- with my previous install is that I'm now running ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0] (Snow Leopard default) rather than 1.8.6. I'm now seeing deprecation warnings relating to OpenSSL when I...

More efficient way to plot x-axis points?

I have been working on a project that requires a bar graph to be populated with price results. The chart displays the number of items within a given price range. For instance, if on amazon there are 9 items within the price range of $0-$10 the x-axis would display $0-$10 and the y-axis would be populated with a value of 9. My bar graph...

simple regex -- replace underscore with a space

Hey, I'm writing my first Rails app, and I'm trying to replace the underscores form an incoming id name with spaces, like this: before: test_string after: test string How can I do this? Sorry if this is a bit of a dumb question, I'm not very familiar with regular expressions... ...

Snow Leopard & Ruby on Rails - SQLite3 issue

I just upgraded to snow leopard. Before, I had everything running fine, but now when I start the server from the terminal I get: => Booting WEBrick => Rails 2.3.3 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2009-08-28 23:18:19] INFO WEBrick 1.3.1 [2009-08-28 23:18:19] INFO ruby 1...

Edit method is creating new records, instead of just updating existing ones

My question is: How do I make the edit/update methods for my profiles controller stop creating new records when I edit a profile page? I have a user model and profile model. user has_one :profile. profile belongs_to :user. My routes.rb looks like this: map.resources :users, :has_one => :profile When a visitor to my app creates a use...

Ruby on Rails broken on Snow Leopard

I tried to run the following command and it says there is nothing to update: adam-lees-macbook-3:ART Adam$ sudo gem update --system Updating RubyGems Nothing to update But I know it's not true because I get this: adam-lees-macbook-3:ART Adam$ gem -v 1.2.0 Then I tried this: adam-lees-macbook-3:ART Adam$ sudo gem install rubygems-u...

Ruby on rails: Staring mongrel server

I know mongrel is the default server for "script/server" but when I do that command I get webrick. (I had it working before with mongrel). Now when I tell is to use mongrel ("script/server mongrel") the server fails to start up in the terminal. I get this: $ script/server mongrel ^C/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/g...

Migration Shorthand

Now in rails we can use t.string instead of t.column using t.string is easy.But t.column is a deprecated feature? any other advantage of using t.datatype other than easiness. Is there any way to convert all current migrations to new style easily. ...