What is the matter with content_for_layout?


#1

Here is my layout file:

My Demands <%= stylesheet_link_tag 'ajax_scaffold', :media => 'all' %> <%= javascript_include_tag 'prototype', 'effects', 'rico_corner', 'ajax_scaffold' %>
<%= @content_for_layout %>

After I start up the Webrick server,the html source will be as follows:

My Demands
My Demands
...

It seems that @content_for_layout will contain all the content include
the part before ,how can it happen? very thanks!


#2

Most likely you have that content in your .rhtml files too

Tauraus wrote:

It seems that @content_for_layout will contain all the content include
the part before ,how can it happen? very thanks!


#3

Cheltis wrote:

Most likely you have that content in your .rhtml files too

Tauraus wrote:

It seems that @content_for_layout will contain all the content include
the part before ,how can it happen? very thanks!

I had examined other rhtml file for times,but it does not exist at all…


#4

Tauraus wrote:

Cheltis wrote:

Most likely you have that content in your .rhtml files too

Tauraus wrote:

It seems that @content_for_layout will contain all the content include
the part before ,how can it happen? very thanks!

I had examined other rhtml file for times,but it does not exist at all…

I got the reason,but I still do not know how to resolve this problem.
It is because of my using pagination.
Here is the demands_controller:

def index
end

def list
@pages = Paginator.new self, Demand.count, 10, @params[:page]
@demands = Demand.find(:all, :order => ‘reply_times DESC’, :limit =>
10, :offset => @pages.current.offset)
end

Here is the index.rhtml:
<%= render_component :controller => ‘demands’, :action => ‘list’ %>
it is generated by the Ajaxscaffold.

if the url refers to : http://127.0.0.1:3000/demands or
http://127.0.0.1:3000/index
then the above error will happen
if the url refers to : http://122.0.0.1:3000/demands/list
then everything is ok

Can anybody tell me the reason? very thanksful!


#5

Cool,aha! Thanks a lot,Cheltis :slight_smile:

Cheltis wrote:

OK, now it looks clear

layout is dublicated because it applied twice

you should put something like this in your controller
layout “your_layout”, :except => ‘list’

however, correct way of doing this would be removing index.rhtml and
changing index action to

def index
list
render :action => ‘list’
end


#6

OK, now it looks clear

layout is dublicated because it applied twice

you should put something like this in your controller
layout “your_layout”, :except => ‘list’

however, correct way of doing this would be removing index.rhtml and
changing index action to

def index
list
render :action => ‘list’
end

Tauraus wrote:

I got the reason,but I still do not know how to resolve this problem.
It is because of my using pagination.
Here is the demands_controller:

def index
end

def list
@pages = Paginator.new self, Demand.count, 10, @params[:page]
@demands = Demand.find(:all, :order => ‘reply_times DESC’, :limit =>
10, :offset => @pages.current.offset)
end

Here is the index.rhtml:
<%= render_component :controller => ‘demands’, :action => ‘list’ %>
it is generated by the Ajaxscaffold.

if the url refers to : http://127.0.0.1:3000/demands or
http://127.0.0.1:3000/index
then the above error will happen
if the url refers to : http://122.0.0.1:3000/demands/list
then everything is ok

Can anybody tell me the reason? very thanksful!