# How to render a partal after form load

**URL:** <https://www.ruby-forum.com/t/how-to-render-a-partal-after-form-load/183798>\
**Category:** Rails\
**Created:** [February 20, 2010, 12:47pm UTC](https://www.ruby-forum.com/t/how-to-render-a-partal-after-form-load/183798 "2010-02-20T12:47:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [February 20, 2010, 12:47pm UTC](https://www.ruby-forum.com/t/how-to-render-a-partal-after-form-load/183798/1 "2010-02-20T12:47:35Z")

</div>

\<% @departmentinfo = Department.find\_all\_by\_company\_id( @user.company\_id, :order =\> "department\_name ASC" ) %\> \<%= render( :partial =\> 'departments', :object =\> @departmentinfo, :locals =\> { :userinfo =\> @user } ) if @departmentinfo %\> \<%= observe\_field("userinfo\_department\_id", :on =\> "changed", :url =\> {:action =\> :update\_roles}, :with =\> "'department\_id='+value")%\> Dear all In my above code all the department gets loaded before the form gets loaded. I want to render my partial after the document is loaded completely. i am not sure how to do this.. Kindly help me out

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [February 20, 2010, 3:54pm UTC](https://www.ruby-forum.com/t/how-to-render-a-partal-after-form-load/183798/2 "2010-02-20T15:54:22Z")

</div>

The short answer is, you can’t - all \<% … %\> code is run, then the  
page is  
displayed.

The long answer is, you could, but there’s probably a better solution.  
The  
way you could do this is to add an event to the document’s onload event  
[How to call scripts - Unobtrusive Javascript](http://onlinetools.org/articles/unobtrusivejavascript/chapter4.html) that  
does an ajax call to the controller that renders the partial.
