Bob Song wrote:
hi, i have a question about partial templates.
there is a table - Topics, it has one field - Title.
there is a text_field form with button, and a partial template under the
form. they are in the same template. the partial can display Titles
which is already in the Topics table.
user enter a string in the form, click the button. the string will save
as Title in Topics table. the partial will display all the data from the
Topics table, including the string which user just entered.
i have been thinking all day, but can't find a solution. can someone
help, give me a solution. thanks very much!
I am doing pretty much this exact same thing. What I have done is to
wrap my partials inside of divs with an id value
'name_of_div_where_partial_is'. I used the form_remote_tag helper to add
to the list without reloading the whole page. Then you can do one of two
1) In the method that is called when you hit the submit button you save
the new Title and then quary to get the old titles and the new title.
Then, you should have the partial already set-up so that variable is
being used to dsiplay the title in that partial. Add the :update option
to the form_remote_tag and it should update without reloading the whole
<%= form_remote_tag :update => 'name_of_div_where_partial_is', . . . %>
2) In the method that gets called when you hit the submit button you can
use the render method with the :update attribute. So something like:
render :update do |page|
page.replace_html 'name_of_div_where_partial_is', :partial =>
What this does it is says to redisplay the partial in the div
overwriting the html currently there.
I use the second way to update a group of two lists that I have on a
single page, where I remove one item from a list that then automatically
gets added to the second list of removed stuff. Hope this helps