Missing partials

I am in the process of converting an application from RoR-2.3.10 to 3.0.1. I have run across the situation where partials are not being rendered at all, whereas the exact same code works fine in Rails2. The form code is:

<div class="headers" id="roles_new_page"> <%- content_tag_for :h2, @role, :header do %>   Add a New role <%= @role.id.to_s -%> <%- end -%> <%=error_messages_for :role %> <%=form_for(@role, :html => {:id => 'new_role_form'}) do |f| %>

  <%= render :partial => 'role_header',               :object => @role -%>   <%= render :partial => 'role_detail',               :object => @role -%>   <%= render :partial => 'shared/effective_period',               :object => @role -%>   <p>   <%=f.submit :Create, :id => :submit_create -%>   </p> <% end %> . . .

All this generates is:

<form accept-charset="UTF-8" action="/roles" class="new_role" id="new_role_form" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>   <p>   <input id="submit_create" name="commit" type="submit" value="Create" /> </p> </form>

Is there anything wrong with using this syntax in Rails3?

James Byrne wrote in post #955566:

I am in the process of converting an application from RoR-2.3.10 to 3.0.1. I have run across the situation where partials are not being rendered at all,

[...]

If the Tattler plugin works with Rails 3 (which I'm not sure of), you might want to use it to make sure that Rails thinks it's rendering the partials.

Best,

Marnen Laibow-Koser wrote in post #955575:

If the Tattler plugin works with Rails 3 (which I'm not sure of), you might want to use it to make sure that Rails thinks it's rendering the partials.

Tattler seems not to work but I found this in a post referring to it:

Tattler doesn't work with Rails 3 anymore. This little bit of code, inspired by it, does.

unless Rails.env.production?   class ActionView::Template     def render_with_comment(*args, &block)       render_result = render_without_comment(*args, &block)       if mime_type.nil? || mime_type === [Mime::HTML, Mime::XML]         ("<!-- TEMPLATE: #{identifier} -->\n" +          render_result +          "\n<!-- ENDTEMPLATE: #{identifier} -->"         ).html_safe       else         render_result       end     end     alias_method_chain :render, :comment   end end

I added the snippet given above to a file in config/initializers called tattler.rb. However, it does not work. I get a stack trace when I run cucumber against the feature that previously simply failed.

So, I am no further ahead. I looked into one of the missing partials. I do not notice anything obviously wrong. The code is here:

James Byrne wrote in post #955607:

I added the snippet given above to a file in config/initializers called tattler.rb. However, it does not work. I get a stack trace when I run cucumber against the feature that previously simply failed.

I discovered my error that was causing tattler to fail. This is what I get now:

It appears that the partials are being called but that the model object is not being passed.

James Byrne wrote in post #955611:

It appears that the partials are being called but that the model object is not being passed.

I discover here ( Getting Up To Speed With Rails 3 ) that the :object => syntax is no longer supported. I suppose that I will eventually discover the current usage.

You can use :locals

It still shows :object in the rails 3 guide, Layouts and Rendering in Rails — Ruby on Rails Guides, section 3.4.4. It does not appear in http://api.rubyonrails.org/classes/ActionView/Partials.html however. Is it the guide that is out of date?

Colin

Colin Law wrote in post #955669:

You can use :locals

I have tried and I evidently am missing something that is obvious to others. The partial I am calling has this:

<%- fields_for(role_header) do |ff| -%>       <%= label role_header.class.to_s.downcase,                 :rolename,                 :'Role Name: ',                 :class => :input_box_label,                 :for => 'input_rolename' -%>       </b> <br />

I have tried this:

<<%=form_for(@role, :html => {:id => :'new_role_form'}) do |f| %>

  <%=render :partial => 'role_header',     :locals => { 'role_header' => @role }-%>

And I get this:

undefined method `model_name' for NilClass:Class (ActionView::Template::Error)       /home/byrnejb/.rvm/gems/ruby-1.8.7-p302/gems/activemodel-3.0.1/lib/active_model/naming.rb:90:in `model_name_from_record_or_class'

I tried this:

  <%=render :partial => 'role_header',     :locals => { :role_header => @role }-%>

And got this:

cannot fill in, no text field, text area or password field with id, name, or label 'Role Name' found.

I tried this:

  <%=render :partial => 'role_header', @role-%>

And got this:

      compile error       /home/byrnejb/Software/Development/Projects/proforma.rails3/app/views/roles/new.html.erb:9: syntax error, unexpected ')', expecting tASSOC       ...tial => 'role_header', @role);                                     ^       /home/byrnejb/Software/Development/Projects/proforma.rails3/app/views/roles/new.html.erb:18: syntax error, unexpected kEND, expecting ')'       '); end              ^       /home/byrnejb/Software/Development/Projects/proforma.rails3/app/views/roles/new.html.erb:26: syntax error, unexpected kENSURE, expecting ')'

I evidently have no idea how to get this to work in Rails3. So, if anyone can see my obvious error then I would be grateful if you would be so kind as to point it out to me.

Colin Law wrote in post #955669:

You can use :locals

I have tried and I evidently am missing something that is obvious to others. The partial I am calling has this:

<%- fields_for(role_header) do |ff| -%> <%= label role_header.class.to_s.downcase, :rolename, :'Role Name: ', :class => :input_box_label, :for => 'input_rolename' -%> </b> <br />

I have tried this:

<<%=form_for(@role, :html => {:id => :'new_role_form'}) do |f| %>

<%=render :partial => 'role_header', :locals => { 'role_header' => @role }-%>

I think it should be :role_header

And I get this:

undefined method `model_name' for NilClass:Class (ActionView::Template::Error) /home/byrnejb/.rvm/gems/ruby-1.8.7-p302/gems/activemodel-3.0.1/lib/active_model/naming.rb:90:in `model_name_from_record_or_class'

I tried this:

<%=render :partial => 'role_header', :locals => { :role_header => @role }-%>

That looks better

And got this:

cannot fill in, no text field, text area or password field with id, name, or label 'Role Name' found.

The fact that it has got past the Class call means we have moved on. It suggests there is a problem with your label statement. I suggest you simplify that to get it working and work back up again.

Colin

Actually it is obvious, look carefully at the Role Name line. What is it supposed to mean?

Clue : and ' do not usually go together like that.

Colin

James Byrne wrote in post #955754:

I evidently have no idea how to get this to work in Rails3. So, if anyone can see my obvious error then I would be grateful if you would be so kind as to point it out to me.

Well, it appears that all along the problem was one of a missing '=' as in:

<%= fields_for

instead of

<%- fields_for

And now everything works, even with :object => @role.

Colin Law wrote in post #955764: [...]

Actually it is obvious, look carefully at the Role Name line. What is it supposed to mean?

Clue : and ' do not usually go together like that.

Wrong. :'Role Name: ' is perfectly legitimate syntax -- it's the way you type symbol literals that contain characters that aren't allowed in Ruby identifiers. The meaning is more or less the same as 'Role Name: '.to_sym .

It's probably not what the OP *wanted*, though. :slight_smile:

Colin

Best,

Well, I never new that you could do that, one lives and learns (for the moment anyway).

Thanks, Marnen.

Colin

Colin Law wrote in post #955799:

'.to_sym .

Well, I never new that you could do that, one lives and learns (for the moment anyway).

Thanks, Marnen.

You're welcome! I think I first came across it when I was developing a Facebook app: FBML tags have the form fb:something (that is, they're in an XML namespace), and I didn't want to use a string for a content_tag tag name if I could help it. Obviously, :fb:something doesn't work, but :'fb:something' does.

You can use a double-quoted string too, and get the expected substitution. Nice way of generating :"#{symbols}" on the fly.

Colin

Best,

Marnen Laibow-Koser wrote in post #955795:

Colin Law wrote in post #955764: [...]

Actually it is obvious, look carefully at the Role Name line. What is it supposed to mean?

Clue : and ' do not usually go together like that.

Wrong. :'Role Name: ' is perfectly legitimate syntax -- it's the way you type symbol literals that contain characters that aren't allowed in Ruby identifiers. The meaning is more or less the same as 'Role Name: '.to_sym .

It's probably not what the OP *wanted*, though. :slight_smile:

Actually, that is an artifact of an earlier implementation which used embedded spaces. I just never got around to removing the quote marks.