Forum: Ruby on Rails RJS call from controller issues javascript that doesn't get

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4eed769209bb61b17593134235873386?d=identicon&s=25 Ovidiu EFTIMIE (Guest)
on 2006-03-29 00:41
(Received via mailing list)
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
==>>>
<table>
    <tr>
        <td><b><%=h @contact.first_name%></b>&nbsp; <%=h
@contact.last_name%></td>
    </tr>
    <tr>
        <td><%=h @contact.address.address%><td>
    </tr>
    <tr>
        <td>Tel : <%h= @contact.address.phone%>&nbsp;
            Fax : <%h= @contact.address.fax%>&nbsp;
            E-mail : <%h= @contact.address.email%>&nbsp;
        <td>
    </tr>
</table>
<<<==

The thing is that my show method gets called  and it returns a java
script call
$("contactInfo").update("<table>\n    <tr>\n
<td><b>aaa</b>&nbsp; aaa</td>\n    </tr>\n    <tr>\n
<td>aaa<td>\n    </tr>\n    <tr>\n        <td>Tel : &nbsp;\n
 Fax : &nbsp;\n            E-mail : &nbsp;\n        <td>\n    </tr>\n
  \n</table> ");

Can anyone tell me how to get my div updated ?

Thanx,
Ovidiu
D707194949c58eb4076f040adf116508?d=identicon&s=25 Bruno Celeste (Guest)
on 2006-03-29 01:02
(Received via mailing list)
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"
4eed769209bb61b17593134235873386?d=identicon&s=25 Ovidiu EFTIMIE (Guest)
on 2006-03-29 08:20
(Received via mailing list)
Actually I have done as you suggested and the result is the same.
page[:contactInfo].replace_html :partial=>"contactInfo" is also valid.
2ccb2f7699267d258faaafce4ee997df?d=identicon&s=25 Cody Fauser (Guest)
on 2006-03-29 20:00
(Received via mailing list)
- 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 <eovidiu@gmail.com> wrote:
> >
> > >   end
> > >         <td><%=h @contact.address.address%><td>
> > > The thing is that my show method gets called  and it returns a java script call
> > > _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Cody Fauser
http://www.codyfauser.com
2ccb2f7699267d258faaafce4ee997df?d=identicon&s=25 Cody Fauser (Guest)
on 2006-03-29 20:15
(Received via mailing list)
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 Fauser
http://www.codyfauser.com
4eed769209bb61b17593134235873386?d=identicon&s=25 Ovidiu EFTIMIE (Guest)
on 2006-03-30 23:22
(Received via mailing list)
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}) %>"
This topic is locked and can not be replied to.