Good notes posted by k776
RSS feed![Default_avatar_30](https://www.gravatar.com/avatar/7e96711a7e6976272ce864a1b0c7cc85?default=http://apidock.com/images/default_avatar_30.png&size=30)
with_exclusive_scope example by Ramon broken in latest Rails
The example Ramon gave works within the model itself, i.e.
class Article def closed with_exclusive_scope { find(:all) } end end
However, from what I can see, this approach does not work within a controller. You may be wanting to use
Article.with_exclusive_scope { find(:all) } #=> "SELECT * FROM 'articles'
But it will error out about find(:all) not existing on ArticlesController. To get around this, you must now do
Article.with_exclusive_scope { Article.find(:all) } #=> "SELECT * FROM 'articles'
In otherwards, find(:all) isn’t being executed in the scope of the model, but in the controller in which its called.
Took me a minute or two to find out, so I thought I’d let others know.
![Default_avatar_30](https://www.gravatar.com/avatar/7e96711a7e6976272ce864a1b0c7cc85?default=http://apidock.com/images/default_avatar_30.png&size=30)
strip_tags method not functioning in controllers, models, or libs
It comes up with an error about white_list_sanitizer undefined in the class you’re using it in. To get around this, use:
ActionController::Base.helpers.strip_tags('string')
To shorten this, add something like this in an initializer:
class String def strip_tags ActionController::Base.helpers.strip_tags(self) end end
then call it with:
'string'.strip_tags
![Default_avatar_30](https://www.gravatar.com/avatar/7e96711a7e6976272ce864a1b0c7cc85?default=http://apidock.com/images/default_avatar_30.png&size=30)
sanitize method not functioning in controllers, models, or libs
It comes up with an error about white_list_sanitizer undefined in the class you’re using it in. To get around this, use:
ActionController::Base.helpers.sanitize('string')
To shorten this, add something like this in an initializer:
class String def sanitize ActionController::Base.helpers.sanitize(self) end end
then call it with:
'string'.sanitize