С 2,4 версий спецификации Сервлета Вам разрешают иметь сервлет в желанном списке файлов. Обратите внимание, что это не может быть URL (таким как/myproject/MyAction.action). Это должен быть именованный сервлет, и Вы не можете передать строку запроса сервлету. Ваш сервлет контроллера должен был бы иметь действие по умолчанию.
<servlet>
<servlet-name>MyController</servlet-name>
<servlet-class>com.example.MyControllerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyController</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>MyController</welcome-file>
</welcome-file-list>
You can check if a content for :sidebar
exists and render the sidebar if true.
Rails 2.3.5 will have a content_for? method. In the meantime, you can use my Helperful Gem.
- if has_content?(:sidebar)
.grid_8
= render :partial => 'shared/search'
= yield
.grid_4
= yield(:sidebar)
- else
.grid_12
= render :partial => 'shared/search'
= yield
Otherwise, you can assume if :sidebar == false then no sidebar.
def sidebar(enable = true, &block)
if enable
content_for :sidebar, &block
else
@fullpage = true
end
end
def fullpage?
!!@fullpage
end
- if fullpage?
.grid_12
= render :partial => 'shared/search'
= yield
- else
.grid_8
= render :partial => 'shared/search'
= yield
.grid_4
= yield(:sidebar)
If you are using Rails 3.x, check answer to a similar question for correct solution. The solution above doesn't work with Rails 3.
Why not use an if condition based on an instance variable set in you controller. Your default looks like it should render with sidebar. So the following code will only render without sidebar, if you've set @disable_sidebar to anything but false or nil.
.container_12.clearfix
= render :partial => 'shared/flashes'
- unless @disable_sidebar
.grid_8
= render :partial => 'shared/search'
= yield
.grid_4
= yield(:sidebar)
- else
.grid_12
= render :partial => 'shared/search'
= yield