Notes posted by sebthemonster

RSS feed
February 14, 2013 - (>= v3.2.8)
1 thank

conditional rescue from does not seem working on Rails 3.2.11

Be careful, conditional rescue_from does not work in Rails 3.2.11

January 10, 2012
0 thanks

with a params constant

If you want to have a params with the same value on all of the urls in this namespace, you can write this :

with a constant param :admin set to true

namespace :admin, :admin => true do
  resources :posts
end

all of the urls like /admin/post have a param :admin with the value true.

It works also with :

scope 'admin', :admin => true do
 ...
end

match 'administration', :admin => true => 'posts#index'

get 'administration', :admin => true

etc…

May 18, 2010
2 thanks

How using Array methods

It’s not possible to use Array methods with a scope because it’s not an Array but an ActiveRecord::NamedScope::Scope :

this

Article.promotion.sum(&:price)

doesn’t run.

But you can use the to_a method to transform the ActiveRecord::NamedScope::Scope to an Array :

Article.promotion.to_a.sum(&:price)