RJS call from controller issues javascript that doesn't get


#1

Hi,
I’m on Rails 1.1 and I have a problem wit RJS
In my cotroller i have
==>>>
def show
@contact = Contact.find(params[:id])
render :update do |page|
page[:contactInfo].replace_html :partial=>“contactInfo”
end
end
<<<===

And my contactInfo partial looks like this and it’s placed inside a div
element
==>>>

<%=h @contact.first_name%>  <%=h @contact.last_name%>
<%=h @contact.address.address%>
Tel : <%h= @contact.address.phone%>  Fax : <%h= @contact.address.fax%>  E-mail : <%h= @contact.address.email%> 
<<<==

The thing is that my show method gets called and it returns a java
script call
$(“contactInfo”).update("

\n \n \n \n \n \n \n \n \n
aaa  aaa
aaa \n
Tel :  \n Fax :  \n E-mail :  \n \n
");

Can anyone tell me how to get my div updated ?

Thanx,
Ovidiu


#2

You have not specified the id element to update in replace_html method
(which expects an id).
You should replace this line that way:

page.replace_html “contactInfo”, :partial => “contactInfo”


#3

Actually I have done as you suggested and the result is the same.
page[:contactInfo].replace_html :partial=>“contactInfo” is also valid.


#4
  • Are you changing the Content-Type of the response? It needs to be
    ‘text/javascript’ to be automatically evaluated by Prototype.

  • Your div has the id ‘contactInfo’?

  • Make sure you aren’t using the :update option in your remote function
    call.

  • Did you run ‘rake rails:update’ to update your JavaScripts?

  • Does popping an alert box work?
    page.alert(‘RJS works!’)

On 3/29/06, Ovidiu EFTIMIE removed_email_address@domain.invalid wrote:

end

<%=h @contact.address.address%>
The thing is that my show method gets called and it returns a java script call

Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Cody F.
http://www.codyfauser.com


#5

Cody … you’re the man:). Thanx a lot !!!
Actualy I was having tha update option set in my remote function call
Now it looks like this

<%= remote_function(:complete =>“new Effect.Highlight(‘contactInfo’ )”,
:url => { :action =>
‘show’,:id=>contact.id}) %>"


#6

To clarify:

  • Are you changing the Content-Type of the response? It needs to be
    ‘text/javascript’ to be automatically evaluated by Prototype.

Make sure you aren’t overwriting the Content-Type. RJS will set it
for you automatically.


Cody F.
http://www.codyfauser.com