Multiple table joins in rails

To rewrite the SQL query you’ve got in your question, I think it should be like the following (though I’m having a hard time fully visualizing your model relationships, so this is a bit of guesswork): RagaContextApplicantsSong. joins(:raga_contest_applicants => [:raga_content_rounds], :contest_cat). group(‘raga_contest_rounds.contest_cat_id’) …such that the joins method takes care of both of the two joins … Read more

ruby integer to boolean

You could use the zero? method. It returns true if 0. If you need to backwards, you could easily negate it to !@system_config.resend.zero?. Or you could extend the Fixnum class, adding a to_b? method, since everything is open and extensible in dynamic languages. class Integer def to_b? !self.zero? end end Ruby API: http://ruby-doc.org/core/classes/Fixnum.html#M001050

rails 3: layout for namespaced routes

I usually have a Base controller class in my namespace, and then have all controllers in that namespace inherit from it. That allows me to put common, namespace specific code in Base and all the controllers in that namespace can take advantage. For example: class Admin::BaseController < ApplicationController layout ‘admin’ before_filter :require_admin_user end class Admin::WidgetsController … Read more

Do routing specs support redirect routes? [RSpec]

Routing specs/tests specialize in testing whether a route maps to a specific controller and action (and maybe some parameters too). I dug into the internals of Rails and Journey a bit. RSpec and Rails (basically, some details left out) use Rails.application.routes.recognize_path to answer the question “is this routable?” For example: $ rails console > Rails.application.routes.recognize_path(“/business_users/1”, … Read more

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