Forum: Ruby on Rails Render No Layout?

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.
5c26728d2db67a78f9097f63ed3c8d37?d=identicon&s=25 Bing (Guest)
on 2006-05-17 10:49
Hi guys,

Am having a problem.

I have this def in my index controller that works like this:

def do_something

$a = variable1
$b = variable2
$c = variable3
$d = ""<script language=\"Javascript\"> \n new Insertion.Bottom('#{$c}',
'#{$a} - #{$b}'); \n </script>"

$trigger = "1"

render(:partial => "do_something")

end

on my do_something.rhtml, my code is this:
<% if $trigger == "1" %>
	<%=$d %>
	<% $trigger = "0" %>
	<% return %>
<% end %>

I get a render with no layout error message. What am I doing wrong?

thanks in advance!

Bing
B26c571d17b3022ab1a98c1a223c32e6?d=identicon&s=25 David Thomson (Guest)
on 2006-05-17 10:55
(Received via mailing list)
On 17/05/06, Bing <sombreroisland@gmail.com> wrote:

> on my do_something.rhtml, my code is this:
> <% if $trigger == "1" %>
>         <%=$d %>
>         <% $trigger = "0" %>
>         <% return %>
> <% end %>
>
> I get a render with no layout error message. What am I doing wrong?

Just guessing, but is it because you have that 'return' in your
do_something.rhtml?

David
E28c35323f624b8b9ed8712e25105454?d=identicon&s=25 Ray Baxter (Guest)
on 2006-05-17 11:34
(Received via mailing list)
Bing wrote:
> $c = variable3
> <% if $trigger == "1" %>
> 	<%=$d %>
> 	<% $trigger = "0" %>
> 	<% return %>
> <% end %>
>
> I get a render with no layout error message. What am I doing wrong?

Partials should be named with a beginning underscore _do_something.rhtml

More likely you want to just take the render(:partial => "do_something")
out of your controller. The default is for every controller action that
doesn't redirect to render a template with the same name as the action,
so the do_something action will render the do_something.rhtml template.

If you want to specific a different template, use render(:action =>
"template_name")

--

Ray
5c26728d2db67a78f9097f63ed3c8d37?d=identicon&s=25 Bing (Guest)
on 2006-05-17 12:04
Hi David,

I need the <%return%> on my rhtml so that I can exit out of my if
condition.

Hi Ray,

Sorry, but yes, our render partial rhtml does have the underscore. so
the page is called _do_something.rhtml. Just the same we had already
used render(:action with no success.

Also, if I may add, def do_something is being executed by a
periodical_call_remote function.

Bing
6dab365a82517fb694650a57ee88e4a4?d=identicon&s=25 j`ey (Guest)
on 2006-05-17 13:12
Bing wrote:
> Hi David,
>
> I need the <%return%> on my rhtml so that I can exit out of my if
> condition.
>
> Hi Ray,
>
> Sorry, but yes, our render partial rhtml does have the underscore. so
> the page is called _do_something.rhtml. Just the same we had already
> used render(:action with no success.
>
> Also, if I may add, def do_something is being executed by a
> periodical_call_remote function.
>
> Bing

You don't need a return statement in the if condition.

j`ey
http://www.eachmapinject.com
(c="amBleQ==\n").unpack(c[1..1]).pop
5c26728d2db67a78f9097f63ed3c8d37?d=identicon&s=25 Bing (Guest)
on 2006-05-17 14:00
j`ey wrote:
> Bing wrote:
>> Hi David,
>>
>> I need the <%return%> on my rhtml so that I can exit out of my if
>> condition.
>>
>> Hi Ray,
>>
>> Sorry, but yes, our render partial rhtml does have the underscore. so
>> the page is called _do_something.rhtml. Just the same we had already
>> used render(:action with no success.
>>
>> Also, if I may add, def do_something is being executed by a
>> periodical_call_remote function.
>>
>> Bing
>
> You don't need a return statement in the if condition.
>
> j`ey
> http://www.eachmapinject.com
> (c="amBleQ==\n").unpack(c[1..1]).pop

Took out the return, doesn't do squat. The main thing I guess is, I
don't see which section does the first render and which section does the
2nd render. there was no explicit statement in the code to make a second
render.
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-05-17 16:47
(Received via mailing list)
On May 17, 2006, at 1:49 AM, Bing wrote:

> $c = variable3
> on my do_something.rhtml, my code is this:
> Bing
Bing-

	Is there any reason you are using global variables? vars with the $
sign are global and can have unexpected behavior when you use them
like you are right now. You should be using instance @vars instead,
the ones with the @ sign.

-Ezra
E28c35323f624b8b9ed8712e25105454?d=identicon&s=25 Ray Baxter (Guest)
on 2006-05-17 17:53
(Received via mailing list)
Bing wrote:

> Sorry, but yes, our render partial rhtml does have the underscore. so
> the page is called _do_something.rhtml. Just the same we had already
> used render(:action with no success.

When you user render :action, the template doesn't begin with an
underscore, correct?

> Also, if I may add, def do_something is being executed by a
> periodical_call_remote function.

Ah. So you have

controller

def periodical_call_remote_function
   do some stuff
   do_something
   What's here?
end

def do_something
   some more stuff defining @thing
   render :action => 'do_something'
end


view

do_something.rhtml

<% display @thing %>


Do you have a periodical_call_remote_function.rhtml?

--

Ray
5c26728d2db67a78f9097f63ed3c8d37?d=identicon&s=25 Bing (Guest)
on 2006-05-18 05:49
Hi Ezra,

The reason I needed to use global variable for the def was because we
needed to pass the value of the variable to the rhtml. Setting it with @
doesn't allow me to do that. We tested it again to make sure and true
enough, while variable c was $c, the values were being passed. When @c,
the values weren't.

Hi Ray,


my periodical call remote is actually found on my rhtml with this line
of code:

<div id="divname"></div>
<%= periodically_call_remote(:update => 'divname', :url => { :action =>
:do_something}, :frequency => 3 ) %>

So it calls do_something from there.

Still having the doublerender! If I tried putting on the
"erase_render_results", it doesn't show the error but it also doesn't
show what I needed to render. It's driving me nuts!

Regards,

Bing
91eb330fb36d1e03c856574dfb77d2bc?d=identicon&s=25 Thibaut Barrère (thbar)
on 2006-05-18 11:34
(Received via mailing list)
> The reason I needed to use global variable for the def was because we
> needed to pass the value of the variable to the rhtml. Setting it with @
> doesn't allow me to do that. We tested it again to make sure and true
> enough, while variable c was $c, the values were being passed. When @c,
> the values weren't.

You have to manage to make it work with @ then! afaik it's really the
way it
should be done (
http://api.rubyonrails.com/classes/ActionControlle...)

Could you post a repro of your issue with @ variables ? (maybe use
longer
variable names also). This way we may be able to understand what's
happening
in there.

Really, you shouldn't use those global variables for this or you'll get
unexpected things ("I see dead people" and stuff :-)

hth

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