Forum: Ruby on Rails Ajax and ruby problem highlighting

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
334ae822566107a2ea2b7a7cb88bd1d6?d=identicon&s=25 brutyn_nick (Guest)
on 2005-11-21 14:14
(Received via mailing list)
hey, i starting to use ajax in my site and i hope that u guys can help

for an simple example, i have a list of users

Lastname 	Firstname
Brutyna 	Andydsfd 	Show 	Edit
Brutynd 	Lucs 	        Show 	Edit
Brutynz 	Nick 	        Show 	Edit

this is the list, when u click on show, u get the ajax "popup" with the
when u click on edit, u get also an ajax "popup", there u can edit the
values. when i click on the the update button (in the edit popup), i
want this
to happen:
-popup closes
-refresh user list
-highlight the edited user
==> all this works with a static id like "user5" (this is the row in the
but i want a dynamic id
(see in edit.rhtml)
  :complete => 'user_updated("user5");' ) %>)

this is my code for the index.rhtml
<% content_for("page_scripts") do -%>

function changeSty(id, newClass){
	//var item = $('items').firstChild;
	//new Effect.Highlight(item);


function user_updated(item) {
	$('form-submit-button').disabled = false;
	//popup becomes hidden
	//mark the edited row
	new Effect.Highlight(item);

function item_loading() {
	$('form-submit-button').disabled = true;'busy');
<% end -%>
<div id="userlist">
<table border="1" width="500px">
<% if @users != nil  %>
		<th colspan="4" style="border-bottom:2px solid #FFF">Users</th>
	<% if !@users.empty?  %>
		<% for user in @users %>
			<tr id="user<%= %>" >
				<td><%= user.last_name %></td>
				<td><%= user.first_name %></td>
				<td><%= link_to_remote ("Show", :update => "div_user",
										 :url => { :action => :show, :id => user },
										 :complete => 'changeSty("div_user","show_popup")' ) %>
				<!--<td><%= link_to_remote ("Show", :complete => "new
Effect.Appear('div_user')", :url => { :action => :show, :id => user })
				<td><%= link_to_remote ("Edit", :update => "div_user",
										 :url => { :action => :edit, :id => user },
										 :complete => 'changeSty("div_user","show_popup")' ) %>
		<% end %>
	<% else %>
		<tr><td colspan="4" class="centered">No entries found...</td></tr>
	<% end %>
<% end %>
<div id="div_user" class="popup"></div>

my edit.rhtml
<div id="info">
<table class="window" cellpadding="0px" cellspacing="0px">
	<tr class="window_top">
		<td>User Info</td>
		<td class="window_close">
			<span class="close">
				<a href="#" onClick="changeSty('info','noshow_link');">Close</a>
		<td colspan="2">
			<%= form_remote_tag ( :url => { :action => :update, :id => @user },
							:update => "userlist" ,
							 :loading => 'item_loading()',
							 :complete => 'user_updated("user5");' ) %>
			<table cellpadding="0px" cellspacing="0px" class="window_content">
						<h2>User details</h2>
						<p><b>Lastname:</b><%= text_field "user", "last_name", :size =>
20, :id =>
'user[last_name]' %></p>
						<p><b>Firstname:</b><%= text_field "user", "first_name", :size =>
20, :id
=> 'user[first_name]' %></p>
						<p><b>Email:</b><%= text_field "user", "email", :size => 20, :id
'user[email]' %></p>
					<td class="right">
						<%= submit_tag("Update", :id => 'form-submit-button') %>
							<span id='busy' style="display: none">Updating...</span>

my controller
class UserController < ApplicationController

	def index
		@users = User.find(:all, :order => "last_name ASC, first_name ASC")
		updated = params[:updated].blank? ? false : params[:updated]
		if updated
			render(:layout => false )

	def show
		user_id = params[:id]
		@user = User.find(:first, :conditions =>['id = ? ', user_id])
		render(:layout => false )

	def edit
		user_id = params[:id]
		@user = User.find(:first, :conditions =>['id = ? ', user_id])
		render(:layout => false )

	def update
		@user = User.find(params[:id])

		@user.last_name = @params[:user][:last_name]
		@user.first_name = @params[:user][:first_name] = @params[:user][:email]
			redirect_to :controller =>'user', :action => 'index', :updated =>
true #dont
think this is a right way to do it, when the update is done, i dont need
render the global layout again
			redirect_to :controller =>'user', :action => 'edit', :id => @user



when i change (in edit.rhtml) the complete stuff:

 :complete => 'user_updated("user5");' ) %>

to all the javascript function like
:complete => 'user_updated("user5");changeSty("info","noshow_link");new
he doesnt want to do all this, and something the layout is fucked up

hope u guys can help me

thanks alot
531eb73f8fbf05a197721d02b4e6aadb?d=identicon&s=25 bogdan.ionescu (Guest)
on 2005-11-21 14:47
(Received via mailing list)
It is difficult for me to follow all the code, so I am suggesting you to
Firefox and watch the javascript console, looking for javascript errors.
What is user5?
On edit.rhtml you should probably have:
<%= form_remote_tag ( :url => { :action => :update, :id => },
:update => "userlist" ,
:loading => 'item_loading()',
 :complete => "user_updated('user#{}');" ) %>

334ae822566107a2ea2b7a7cb88bd1d6?d=identicon&s=25 brutyn_nick (Guest)
on 2005-11-21 15:03
(Received via mailing list)
user5 is just to make a unique id , text "user" and its id, "cuz i
thougth ids
couldnt start with numbers

yeah thanks for that
changed it to
<% .........

:complete =>
"new EFfect.Highlight('user#{}');
user_updated();changeSty('info','noshow_link');" ) %>

And how can i now make the popup draggable???

<%= draggable_element("div_user", :revert => true) %> doesnt seem to

div => div_user is the div that is already on the index page (invisible,
position absolute)

div => info is the div with the table and its user info (popup)

thanks in advance
334ae822566107a2ea2b7a7cb88bd1d6?d=identicon&s=25 brutyn_nick (Guest)
on 2005-11-21 15:59
(Received via mailing list)
i have fixed the previous error, no thats works, but now i want to
create a new
user and highlight it after creation

with my previous code in edit.html, i now have in new.rhtml

<%= form_remote_tag ( :url => { :action => :update, :id => @user },
	:update => "userlist" ,
	:loading => 'item_loading()',
	:complete => "new Effect.Highlight('user#{}');
) %>

<%= form_remote_tag ( :url => { :action => :create, :id => @user },
	:update => "userlist" ,
	 :loading => 'item_loading()',
	:complete => "user_updated();changeSty('info','noshow_link');" ) %>

here i also need new Effect.Highlight('user#{}') , but i dont
now the
user id yet, cuz i need to created if first, can anyone help here?
This topic is locked and can not be replied to.