Forum: Ruby on Rails RJS templates not found

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.
Arch S. (Guest)
on 2006-04-17 03:10
I am running Rails 1.10 and wanted to check out the RJS templates.
Rails doesn't seem to find them.

I did issue the rake comment update_javascripts and that did not correct
the problem.  RJS is part of 1.1 right?

Any ideas?

Thanks.
Arch S. (Guest)
on 2006-04-17 05:19
Arch S. wrote:
> I am running Rails 1.10 and wanted to check out the RJS templates.
> Rails doesn't seem to find them.
>
> I did issue the rake comment update_javascripts and that did not correct
> the problem.  RJS is part of 1.1 right?
>
> Any ideas?
>
> Thanks.

Apparently I was still on 1.0.  So I am getting the RJS templates
recgonized now, however I am now getting weird output:

page display:

# try { new Insertion.Bottom("test_1", "Fox
# "); new Effect.Highlight("list",{duration:3}); } catch (e) {
alert('RJS error:\n\n' + e.toString()); alert('new
Insertion.Bottom(\"test_1\", \"Fox
\");\nnew Effect.Highlight(\"list\",{duration:3});'); throw e }

controller:
  def take_test2

  end

rjs template:
page.insert_html :bottom, 'test_1',
                 content_tag("li", "Fox")
page.visual_effect :highlight, 'list', :duration => 3
Arch S. (Guest)
on 2006-04-17 05:51
I did some more testing.  Even turned debugging off for RJS templates
but still I am getting the source displayed on my page.

So for this RJS template:
## rjs template
page.insert_html :bottom, "test_1", :partial => "take_test"
page.visual_effect :highlight, "test_1", :duration => 10

## rhtml partial
<div class="take_test">
  <h3>Post</h3>
  <p>post text</p>
</div>


I am getting this displayed in the browser:

new Insertion.Bottom("test_1", "
\n
Post
\n

post text
\n
"); new Effect.Highlight("test_1",{duration:10});
Jeff C. (Guest)
on 2006-04-17 06:02
Arch S. wrote:
> I did some more testing.  Even turned debugging off for RJS templates
> but still I am getting the source displayed on my page.
>
> So for this RJS template:
> ## rjs template
> page.insert_html :bottom, "test_1", :partial => "take_test"
> page.visual_effect :highlight, "test_1", :duration => 10
>
> ## rhtml partial
> <div class="take_test">
>   <h3>Post</h3>
>   <p>post text</p>
> </div>
>
>
> I am getting this displayed in the browser:
>
> new Insertion.Bottom("test_1", "
> \n
> Post
> \n
>
> post text
> \n
> "); new Effect.Highlight("test_1",{duration:10});

When you link to the action which uses RJS, use link_to_remote instead
of link_to.

Jeff C.man
Arch S. (Guest)
on 2006-04-17 06:27
Jeff C.man wrote:

>
> When you link to the action which uses RJS, use link_to_remote instead
> of link_to.
>
> Jeff C.man

Yep I am using this call:


<div id="test_1">
  <p><%= link_to_remote("Take Kwiz RJS",:update =>"test_1",:url =>{
:action => "take_test2", :id => test.id}) %> </p>
</div>
Alain R. (Guest)
on 2006-04-17 10:03
(Received via mailing list)
Arch
     > <div id="test_1"> <p><%= link_to_remote("Take Kwiz RJS",:update
=>"test_1",:url =>{
     > :action => "take_test2", :id => test.id}) %> </p>
     > </div>

To summarize, your RJS ends up as plain test in your web page instead of
being inserted and executed.
Don't you're have a filter somewhere that sets the content type to text?

Alain
Ezra Z. (Guest)
on 2006-04-17 10:16
(Received via mailing list)
On Apr 16, 2006, at 11:00 PM, Alain R. wrote:

>
> Alain
>
> _______________________________________________


	Did you make sure to put the  <%= javascript_include_tag :defaults %
 > in the head of the page getting served?

-Ezra
Arch S. (Guest)
on 2006-04-17 10:17
Alain R. wrote:
> Arch
>      > <div id="test_1"> <p><%= link_to_remote("Take Kwiz RJS",:update
> =>"test_1",:url =>{
>      > :action => "take_test2", :id => test.id}) %> </p>
>      > </div>
>
> To summarize, your RJS ends up as plain test in your web page instead of
> being inserted and executed.
> Don't you're have a filter somewhere that sets the content type to text?
>
> Alain


Correct.  The content type is being set to text in my header:

  <head>
    <meta http-equiv="Content-Type" content="text/javascript"
charset=UTF-8" />
    <link href="/stylesheets/main.css" media="all" rel="Stylesheet"
type="text/css" />
    <script src="/javascripts/prototype.js"
type="text/javascript"></script>
<script src="/javascripts/effects.js" type="text/javascript"></script>
<script src="/javascripts/dragdrop.js" type="text/javascript"></script>
<script src="/javascripts/controls.js" type="text/javascript"></script>
<script src="/javascripts/application.js"
type="text/javascript"></script>
  </head>

I've also tried

<meta http-equiv="Content-Type" content="text/html" charset=UTF-8" />

And that did not help either.
Jeff C. (Guest)
on 2006-04-17 10:19
Arch S. wrote:
> Jeff C.man wrote:
>
>>
>> When you link to the action which uses RJS, use link_to_remote instead
>> of link_to.
>>
>> Jeff C.man
>
> Yep I am using this call:
>
>
> <div id="test_1">
>   <p><%= link_to_remote("Take Kwiz RJS",:update =>"test_1",:url =>{
> :action => "take_test2", :id => test.id}) %> </p>
> </div>

Try removing the :update parameter from your link_to_remote call.

I believe what's happening is that link_to_remote is sending the result
of the call into the DIV "test_1", like it would if you'd called a
partial.  But since you're dealing with RJS, your RJS calls will specify
which DIV to update.

Jeff C.man
Arch S. (Guest)
on 2006-04-17 10:20
Ezra Z. wrote:
> On Apr 16, 2006, at 11:00 PM, Alain R. wrote:
>
>>
>> Alain
>>
>> _______________________________________________
>
>
> 	Did you make sure to put the  <%= javascript_include_tag :defaults %
>  > in the head of the page getting served?
>
> -Ezra

Yes, here is my layout:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...
<html>
  <head>
    <title>Rails Application</title>
    <meta http-equiv="Content-Type" content="text/javascript"
charset=UTF-8" />
    <%= stylesheet_link_tag "main", :media => "all" %>
    <%= javascript_include_tag :defaults %>
  </head>
Arch S. (Guest)
on 2006-04-17 10:24
Jeff C.man wrote:

>
> Try removing the :update parameter from your link_to_remote call.
>
> I believe what's happening is that link_to_remote is sending the result
> of the call into the DIV "test_1", like it would if you'd called a
> partial.  But since you're dealing with RJS, your RJS calls will specify
> which DIV to update.
>
> Jeff C.man

That was it!  Damn this one was really throwing me.

Basically I had my whole app working with partials but wanted to try the
RJS templates in 1.1.0, so the :udpate parameters were everywhere and
thus none of my templates were working.

What I don't understand though is the RJS template was still being hit .
. . oh wait I see . . .  it was treating the the code block as the input
and not actually running the code.  Right?
Jeff C. (Guest)
on 2006-04-17 10:26
Arch S. wrote:
> Jeff C.man wrote:
>
>>
>> Try removing the :update parameter from your link_to_remote call.
>>
>> I believe what's happening is that link_to_remote is sending the result
>> of the call into the DIV "test_1", like it would if you'd called a
>> partial.  But since you're dealing with RJS, your RJS calls will specify
>> which DIV to update.
>>
>> Jeff C.man
>
> That was it!  Damn this one was really throwing me.
>
> Basically I had my whole app working with partials but wanted to try the
> RJS templates in 1.1.0, so the :udpate parameters were everywhere and
> thus none of my templates were working.
>
> What I don't understand though is the RJS template was still being hit .
> . . oh wait I see . . .  it was treating the the code block as the input
> and not actually running the code.  Right?

I believe that's it--it was taking the JavaScript generated by the RJS
template as the content and updating the specified DIV with it--rather
than executing the JavaScript as code.

I got confused by this at the start myself. :)

Jeff
This topic is locked and can not be replied to.