AHA! I figured it out. If anyone else is interested, here''s what I
learned...
It is indeed a fact that my instance variable ''@issue''
disappeared from
scope once the template called another function via ajax. A controller
function foo() can set an instance var like @myfoovalue, and the
associated template, foo.rhtml, will have access to that var via "<%=
@myfoovalue %>" but if that template calls other code, the var is not
carried along.
So, the trick is to use the session object to carry this state around.
Using my earlier example, here''s how I did it:
Within issue_controller.rb:
def edit
@issue = Issue.find(params[:id])
# save the issue id into the session object
session[:curr_issue] = @issue
# default behavior is to render edit.rhtml now
end
edit.rhtml sets up the form, and it calls partial render on _form.rhtml
which looks like this:
<!--[form:issue]-->
<%= link_to_remote(''Description'',
:update => ''tabbed_area'',
:url => { :controller => ''issues'',
:action => :tab_description_fields } ) %>
<%= link_to_remote(''Property Details'',
:update => ''tabbed_area'',
:url => { :controller => ''issues'',
:action => :tab_property_fields } ) %>
<%= link_to_remote(''Financials'',
:update => ''tabbed_area'',
:url => { :controller => ''issues'',
:action => :tab_financial_fields } ) %>
<%= link_to_remote(''Messages'',
:update => ''tabbed_area'',
:url => { :controller => ''issues'',
:action => :tab_message_fields } ) %>
<br>
<br>
<div id=''tabbed_area''>
</div>
<!--[eoform:issue]-->
Now, back in issue_controller.rb, the functions that correlate to tabs
on the notebook look like:
# these functions call their associated *.rhtml files without
rendering the standard templates,
# e.g. tab_financial_fields will trigger tag_financial_fields.rhtml
def tab_financial_fields
@issue = session[:curr_issue]
render(:layout => false )
end
def tab_description_fields
@issue = session[:curr_issue]
render(:layout => false )
end
def tab_property_fields
@issue = session[:curr_issue]
render(:layout => false )
end
def tab_message_fields
@issue = session[:curr_issue]
render(:layout => false )
end
Now, the templates that are associated with the tab_* functions get a
valid @issue instance variable and all their text_area calls work just
dandy.
- David
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---