Hi~
Hi Ezra,
Your advice was a great boost forward. But I still have a problem.
BTW, I'm running:
WinXP-Pro/SP2, MySQL 5.0.15-nt, Ruby 1.8.2-15, Rails 1.1.4
SciTE 1.59, FireFox 1.2.0.7, Java JDK 1.5.0_06
I used the before_filter :setup_tables, :show_session That allowed my
show_session to method to work both upon entry and exit from the
ApplicationController's instantiation.
Show session also worked in app\controllers\MainController.rb#welcome
However, it failed in app\views\main\welcome.rhtml with the error:
ActionView::TemplateError (undefined local variable or method
`show_session'
So I think I need to move it's def to someplace higher than both
controllers and views. How can I do that? Or should I make it a global
function somehow?
If you don't mind an additional question, please give me your
assessment of a rescue clause I added to show_session, as shown below.
Thanks for your outstanding advice.
Regards,
Richard
class ApplicationController < ActionController::Base
before_filter :setup_tables, :show_session
layout "base"
logger.debug "==================================="
logger.debug "Entering app\\controllers\\application.rb (top level)"
logger.debug "==================================="
def setup_tables
tables = [:customers, :invoices, :payments]
tables.each { |tbl| session[tbl] = {} }
session[:tables] = tables
end
def show_session
logger.debug "Application tables:"
nTables = session[:tables].length
(0..(nTables-1)).each { |i|
symTbl = session[:tables][i]
objElement = session[symTbl]
logger.debug "\t" + symTbl.to_s + " => " + objElement.inspect
}
rescue
raise "session[:tables] => nil" unless session[:tables]
raise "nTables => #{nTables}" unless nTables != 3
raise "symTbl => nil for session[:tables][#{i}]" unless symTbl
raise "objElement => nil for session[#{symTbl}]" unless objElement
end
protected
def sort_clause(model, column, *order)
[snip]
end
logger.debug "^^^^^^^^^^^^^^^^^^^^^^^"
logger.debug "Leaving app\\controllers\\application.rb (top level)"
logger.debug "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"
end
Lets rewrite some of this code to make it clearer.
class ApplicationController < ActionController::Base
before_filter :setup_tables, :show_session
layout "base"
def setup_tables
tables = [:customers, :invoices, :payments].map{ |tbl| session[tbl] = {}; tbl }
session[:tables] = tables
end
<snip>
end
SO I think you can leave out the show_session method. And when you want to see whats in the session in your view use this instead:
<%= debug(session) %>
That will show you everything that is currently in the session in a nice yaml formatted view. If you really want to be able to call the show_session method from a view then you can do that by useing helper_method like this:
helper_method :show_session
put that in your application.rb class right after the definition of show_session.
Cheers-
-- Ezra Zygmuntowicz-- Lead Rails Architect
-- ez@engineyard.com
-- Engine Yard, Serious Rails Hosting
-- Reliability, Ease of Use, Scalability
-- (866) 518-YARD (9273)