# HOWTO: Render partial in div

**URL:** <https://www.ruby-forum.com/t/howto-render-partial-in-div/51619>\
**Category:** Rails\
**Created:** [January 4, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/howto-render-partial-in-div/51619 "2006-01-04T18:12:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keith\_Donaldson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/50afbb/32.png) [@Keith\_Donaldson](https://www.ruby-forum.com/u/Keith_Donaldson)\
**Post date:** [January 4, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/howto-render-partial-in-div/51619/1 "2006-01-04T18:12:40Z")

</div>

Hey-

I’m using ROR 1.0 and [script.aculo.us](http://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

- New Plog
 \<% for archive in @archives %\> - \> \<%= archive.call\_end %\> 
 \<% end %\> - Contacts
- Archive

---

<div class="post-metadata">

**Author:** ![Keith\_Donaldson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/50afbb/32.png) [@Keith\_Donaldson](https://www.ruby-forum.com/u/Keith_Donaldson)\
**Post date:** [January 4, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/howto-render-partial-in-div/51619/2 "2006-01-04T18:14:23Z")

</div>

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:

… lot of stuff …

 \<%= @content\_for\_layout %\>

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
> - Archive
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ 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!

---

<div class="post-metadata">

**Author:** ![Keith\_Donaldson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/50afbb/32.png) [@Keith\_Donaldson](https://www.ruby-forum.com/u/Keith_Donaldson)\
**Post date:** [January 4, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/howto-render-partial-in-div/51619/3 "2006-01-04T18:14:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Keith\_Donaldson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/50afbb/32.png) [@Keith\_Donaldson](https://www.ruby-forum.com/u/Keith_Donaldson)\
**Post date:** [January 4, 2006, 7:51pm UTC](https://www.ruby-forum.com/t/howto-render-partial-in-div/51619/4 "2006-01-04T19:51:17Z")

</div>

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] [Peak Obsession](http://api.rubyonrails.com/classes/ActionView/Helpers/)  
JavaScriptHelper.html#M000435  
[2] [http://www.rubyonrails.com/media/video/rails-ajax.mov](http://www.rubyonrails.com/media/video/rails-ajax.mov)

---

<div class="post-metadata">

**Author:** ![Keith\_Donaldson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/50afbb/32.png) [@Keith\_Donaldson](https://www.ruby-forum.com/u/Keith_Donaldson)\
**Post date:** [January 5, 2006, 4:19am UTC](https://www.ruby-forum.com/t/howto-render-partial-in-div/51619/5 "2006-01-05T04:19:07Z")

</div>

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
