HOWTO: Render partial in div

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

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 [email protected] 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!

    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.

    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
    JavaScriptHelper.html#M000435
    [2] http://www.rubyonrails.com/media/video/rails-ajax.mov

    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