Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial rendering not shown

Rails 3.0.7, Windows 7, NetBeans 6.9.1, JRuby 1.5.1, Ruby 1.8.7

I have app/views/browsing/index.rhtml with this relevant part, focus on the render call:

<table>
  <tr>
    <th><em><%=I18n.t('browsing.actions')%></em></th>
    <% colnames = @_controller.model_class.column_names %>
    <% colnames.each do |name| %>
    <% render  :partial => 'browsing/header_field', :locals => {:name => name} %>
    <% end %>
  </tr>

And I have app/views/browsing/_header_field.rhtml with the following content:

<% puts "DEBUG: rendering " + name + " field." %>
<% if @_controller.orderables.include?(name.to_sym) %>
<%
  otext = ''
  oopts = @_controller.orderings[name];
  if !oopts.nil?
    otext += ' ' + (oopts[:is_asc] ? '↓' : '↑')
    otext += '<span class="small">'+oopts[:prio].to_s+'</span>'
  end
%>
<th><%=link_to( name.tr('_',' '), { :controller => controller_path, :action => 'index', :o => name }, {:class => 'sort'} )%>
<%=((otext=='' || @_controller.orderings.size<=1) ? raw(otext) : link_to(raw(otext), { :controller => controller_path, :action => 'index', :o => name, :x => true }, {:class => 'delete_sort', :title => I18n.t('browsing.delete_sort')}))%></th>
<% else %>
<th><%=name.tr('_',' ')%></th>
<% end %>

The debug-print (first line) is executed properly, I can see it in the output window. I can use the NetBeans IDE to watch the execution of this file line by line, it happens as it is expected

The problem is that the results of this rendering are somehow dropped out on the window, there is nothing (no table header cells) in the final rendered HTML. That is rendered (only relevant part):

<table>
  <tr>
    <th><em>Actions</em></th>
  </tr>

The output window produces this:

DEBUG: rendering id field.
DEBUG: rendering inm_device_id field.
DEBUG: rendering changes_id field.

Started GET "/changes_and_devices" for 127.0.0.1 at Wed Jun 08 11:50:01 +0200 2011
  Processing by ChangesAndDevicesController#index as HTML
  ChangeAndDevice Load (2.0ms)  SELECT `changes_and_devices`.* FROM `changes_and_devices` ORDER BY id desc LIMIT 20 OFFSET 0
  SQL (18.0ms)  SELECT COUNT(*) FROM `changes_and_devices`
Rendered browsing/_header_field.rhtml (6.0ms)
Rendered browsing/_header_field.rhtml (6.0ms)
Rendered browsing/_header_field.rhtml (5.0ms)
Rendered browsing/index.rhtml within layouts/application (189.0ms)
Completed 200 OK in 245ms (Views: 207.0ms | ActiveRecord: 20.0ms)

All hints are welcome! Thanks in advance!

like image 662
Notinlist Avatar asked Jun 08 '11 10:06

Notinlist


People also ask

How do I render a partial view in main view?

Rendering a Partial View You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html. RenderAction() .

What is partial rendering?

Partial-Page Rendering Features The primary features of ASP.NET that support partial-page rendering are: A declarative model that works like ASP.NET server controls. In many scenarios, you can specify partial-page rendering using only declarative markup.

What is render partial in Rails?

Rails Guides describes partials this way: Partial templates - usually just called "partials" - are another device for breaking the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.

What is page rendering in ASP net?

Page rendering - At this stage, view state for the page and all controls are saved. The page calls the Render method for each control and the output of rendering is written to the OutputStream class of the Response property of page.


1 Answers

Yep, <% only evaluates where <%= also displays evaluated code.

You need to change
<% render :partial => 'browsing/header_field', :locals => {:name => name} %> to
<%= render :partial => 'browsing/header_field', :locals => {:name => name} %>

like image 132
pdu Avatar answered Sep 18 '22 15:09

pdu