Forum: Ruby on Rails HOWTO: Render partial in div

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Keith Donaldson (Guest)
on 2006-01-04 19:12
(Received via mailing list)
Hey-

I'm using ROR 1.0 and script.aculo.us 1.5.1.  I've been trying
unsuccessfully to render a partial in a DIV, but can't seem to get the
right combination of stuff to make it work.  There seems to be a few
different ways of going about it.  Right now I can render a partial.
What do I need to to render the partial in a div?  Here is what it
looks like so far:

#  index.rhtml
<%= start_form_tag :action => 'search' %>
Enter Student Name:  <%= text_field_with_auto_complete :student,
:full_name %>
<%= submit_tag "Get Student Records" %>
<%= end_form_tag %>

# CONTROLLER
def search
	# Get all the PLogs associated with user_id, student_id
	studentid = params[:student]
	fullname = studentid[:full_name]
	name = Student.find_by_full_name(fullname)
	@archives = PhoneLog.find(:all,
		:conditions => ["user_id = ?  AND student_id = ?",
@session['user'].id, name.id])

	# Render the tabs
	render :partial => 'tabs'
end


# _tabs.rhtml
<div id="tabs">
<ul>
	<li><a href="#" onclick="Effect.Appear('new_plog');
Effect.SwitchOff('contentcenter'); return false;"><span>New
Plog</span></a></li>
		<% for archive in @archives %>
			<li><a href="#" title= <%= archive.id %> ><span> <%=
archive.call_end %> </span></a></li>
		<% end %>
	<li><a href="#" title="contacts"><span>Contacts</span></a></li>
	<li><a href="#" title="archive"><span>Archive</span></a></li>
</ul>
</div>
Gerard (Guest)
on 2006-01-04 19:14
(Received via mailing list)
Keith,

under "/app/views/layout/" you put a [controllername].rhtml with a bunch
of
html headers and what not (yes or no generated with some more ruby
code), and
the magical tag:
<html>
<head></head>
<body>

 ... lot of stuff ...

<div id="whateveryoulike">
	<%= @content_for_layout %>
</div>

</body>

Rails will use this and replace the <%= @content_for_layout %> tag with
all
the generated output from your partial.

Is that what you were looking for?

Regards,

Gerard.



On Wednesday 04 January 2006 15:13, Keith Donaldson tried to type
something
like:
> <%= start_form_tag :action => 'search' %>
> 	@archives = PhoneLog.find(:all,
> # _tabs.rhtml
> 	<li><a href="#" title="archive"><span>Archive</span></a></li>
> </ul>
> </div>
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails

--
"Who cares if it doesn't do anything?  It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

My $Grtz =~ Gerard;
~
:wq!
Keith Donaldson (Guest)
on 2006-01-04 19:14
(Received via mailing list)
Thanks Gerard:

I guess I left out part of the story.  I'm looking for AJAX-type
solution that will update a DIV after the user has submitted a form.

Thanks for your help.
Jarkko L. (Guest)
on 2006-01-04 20:51
(Received via mailing list)
On 4.1.2006, at 18.47, Keith Donaldson wrote:

> Thanks Gerard:
>
> I guess I left out part of the story.  I'm looking for AJAX-type
> solution that will update a DIV after the user has submitted a form.

You need to use form_remote_tag instead of normal form_tag to make it
ajax-y.

<%= form_remote_tag(:url => { :controller => "trainingparts",
                               :action => "add_part_with_ajax",
                               :id => @training },
                     :update => 'details',
                     :loading => "$('new-part-desc').innerHTML =
'Saving...'",
                     :complete => "$('new-part-desc').innerHTML =
'Add a part to training'; Field.clear
('trainingpart_hrs','trainingpart_mins', 'trainingpart_secs',
'trainingpart_length')") %>

The :update parameter is where you need to put the id of the div you
want updated. See the complete api [1] for more details. The Rails
AJAX video [2] is also worth watching.

//jarkko

[1] http://api.rubyonrails.com/classes/ActionView/Helpers/
JavaScriptHelper.html#M000435
[2] http://www.rubyonrails.com/media/video/rails-ajax.mov
Keith Donaldson (Guest)
on 2006-01-05 05:19
(Received via mailing list)
Success!

I had to change the form tag in the view:

<%= form_remote_tag(:url => { :controller => "plog",
								:action => "search",
								:id => @archives },
								:update => 'tabs') %>
	Enter Student Name:  <%= text_field_with_auto_complete :student,
:full_name%>
	<%= submit_tag "Get Student Records" %>
<%= end_form_tag %>

.... I tried using the form_remote_tag before but had not used :id.
My guess this makes it work.  Where can you find documentation that
explains what CALLBACKS and AJAX_OPTIONS?

I also removed the div tags from my partial.

Thanks for the help.

kd
This topic is locked and can not be replied to.