Mongoid / Mongodb and querying embedded documents

You can query embedded documents, just qualify the name. Now, this will return all Authors that have books that match your query. If Author is defined as having many :books (and book is an embedded::document) @authors_with_sewid = Author.where(“books.name” => “sewid”).all You’d then need to iterate over the authors and extract the books.

Where’s root_path or root_url?

These helpers exist, but you have to set your root url before, in config/routes.rb: root :to => “controller#action” You can use root_url and root_path afterwards. Be warned that there’s a catch when doing redirections with the _path helpers, you should use the _url ones when redirecting (see @LanguagesNamedAfterCoffee’s comment for the details).

How can I delete specific jobs from Resque queue without clearing the whole queue?

In resque’s sources (Job class) there’s such method, guess it’s what you need 🙂 # Removes a job from a queue. Expects a string queue name, a # string class name, and, optionally, args. # # Returns the number of jobs destroyed. # # If no args are provided, it will remove all jobs of … Read more

Seeding file uploads with CarrierWave, Rails 3

Turns out the documentation for CarrierWave is slightly wrong. There is a more up to date piece of code in the README at the GitHub repository for the project. In a nutshell, though: pi = ProductImage.create!(:product => product) pi.image.store!(File.open(File.join(Rails.root, ‘test.jpg’))) product.product_images << pi product.save!

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)