Ajax - Basic highlighting example

Just wondering if anyone could help me wrap my mind around some of this
ajax stuff and how to get some of those rjs partials to work (if even
necessary).

I was thinking of having a page that would be something like:
(index.rhtml)

<%= javascript_include_tag :defaults %> <% for each user in @users %>
<%= end_form_tag %>

<% end %>

From the examples I’ve seen the controller would have something like

class TestController < ApplicationController
def index
@users = User.find(:all)
end

def highlightName
@uID = params[:id]
#… some magic goes here
redirect_to_index unless request.xhr?
end

def redirect_to_index()
redirect_to :action => :index
end
end

I know I’m missing something here, but the thing’s ive tried haven’t
provided me much feed back on whats happening behind the scenes.

Consider spending $9 @ peepcode to download the 45-min. RJS screencast,
a
rails pro talks you through it all.
http://www.peepcode.com/articles/2006/08/13/rjs-templates

-Ryan

Hi Mic,

If you want you highlightName Action to render a partial, you need to
omit your redirect statement. Each action can only have one redirect
or render statement. If you omit the redirect statement, the
controller will look for an rhtml, rjs or rxml document in the folder
associated with your controller.

In your case it would be app/views/test/highlight_name.rhtml

Put whatever rjs logic you want in there, and rails will take care of
the rest.

Hope that helps

-josh

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs