RJS call from controller issues javascript that doesn't get

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

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”

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

  • 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 [email protected] 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
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


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

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}) %>"

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