These are things I occasionally need to use in Rails and waste ages re-finding each time.
Stop ActiveRecord Logging to the Console when I run ./script/server
config.active_record.logger = Logger.new("/dev/null")Problems:
- Migrations fail
References:
Call Helper Methods in a Controller
When it’s overkill to use a partial, sometimes you need to format text to respond to an AJAX call.
The trick is to use @template:
The Helper
module FoosHelper
def bazify(foo)
{ :qux => "%.2f" % foo.attrib }
end
endThe Controller
class FoosController < ApplicationController
def bar
foo = Foo.find(params[:id])
render :text => @template.bazify(bar).to_json
end
end