class AnyController < ApplicationController
def index
logger.debug @template.inspect #=> #
end
end
27 Apr 2012
Accessing ActionView::Base in a ActionController in Rails 2.3
just came accross an instance variable of an ActionView::Base in ActionController, which is @template;
Labels:
Ruby/ Ruby on Rails
22 Apr 2012
Note: How to show SQL in Rails Console
Just add the following lines into config/environment.rb. This switches default logger to STDOUT.
# Render SQL in Rails Console
if "irb" == $0
require 'logger'
if ENV.include?('RAILS_ENV')&&
!Object.const_defined?('RAILS_DEFAULT_LOGGER')
Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
else
ActiveRecord::Base.logger = Logger.new(STDOUT)
end
end
Labels:
Ruby/ Ruby on Rails
8 Apr 2012
script/consoleでhelper, routing
- 下記に追記
いつのバージョンからか(少なくとも2.3.14からは)名前付きルートはscript/consoleを立ち上げた時点でlink_to はhelperというActionView::Baseのインスタンスからアクセスできて、ダイナミックルートはappというActionController::Integration::Sessionのインスタンスからアクセスできるようになっていました。
http://blog.p.latyp.us/2008/03/calling-helpers-in-rails-console.html
--------------------------------
- コンソールで名前付きルート
Testing Named Routes in the Rails Consoleからまんま拝借。
default_url_optionsは名前のとおり、/parent_controller/:host/child_controller/:idといった定義に対して以下の用にコンソールで名前付きパスのデフォルトのオプションを指定してくれる。
action_controller_path(:id => 23)
=> "/parent_controller/watever/child_controller/23"
belong_toなんかでリソースがネストしてる時に便利。
rs = ActionController::Routing::Routes
rs.recognize_path action_controller_path(:id => 23), :method => 'GET'
とかで、params => {:host => 'whatever', :id => '23'}とかがパラメータとして渡ってくるはず。試してない。
- Helperをコンソールで
いつのバージョンからか(少なくとも2.3.14からは)名前付きルートはscript/consoleを立ち上げた時点でlink_to はhelperというActionView::Baseのインスタンスからアクセスできて、ダイナミックルートはappというActionController::Integration::Sessionのインスタンスからアクセスできるようになっていました。
http://blog.p.latyp.us/2008/03/calling-helpers-in-rails-console.html
--------------------------------
- コンソールで名前付きルート
Testing Named Routes in the Rails Consoleからまんま拝借。
include ActionController::UrlWriter default_url_options[:host] = 'whatever'
default_url_optionsは名前のとおり、/parent_controller/:host/child_controller/:idといった定義に対して以下の用にコンソールで名前付きパスのデフォルトのオプションを指定してくれる。
action_controller_path(:id => 23)
=> "/parent_controller/watever/child_controller/23"
belong_toなんかでリソースがネストしてる時に便利。
rs = ActionController::Routing::Routes
rs.recognize_path action_controller_path(:id => 23), :method => 'GET'
とかで、params => {:host => 'whatever', :id => '23'}とかがパラメータとして渡ってくるはず。試してない。
- Helperをコンソールで
include HelperYouWantToRun #使いたいhelperをincludeする。 helper.method_you_want_to_run
Labels:
Ruby/ Ruby on Rails
Subscribe to:
Comments (Atom)