This project is archived and is in readonly mode.
new smart render misses arguments
-
Jeffrey Hardy
ActionView::Base#render != ActionController::Base#render. The new, "smart" rendering isn't in AV::Base#render. This confused me too.
-
thedarkone
You need to call render like this:
<%= render 'open_hours', :foo => 'bar' %> -
ippa
@Jeffrey: right, but.. both my snippets Does render the correct partial. The confusing part is that the :locals param Only works when I explicity use :partial.
@thedarkone: Thanks for the shortcut to :locals, but the same "problem" shows itself in others forms too, this is another example:
<%= render :partial => "kids/kid_presentation", :collection => @kids, :as => :kid %> ## Renders the correct partial, defining the variable "kid" for the items in the collection in the view.
<%= render "kids/kid_presentation", :collection => @kids, :as => :kid %> ## Renders the correct partial, but the variable "kid" is undefined in the view.
Shouldn't both work since they both understand that it's a partial?
-
Jeffrey Hardy
When rendering using a string as the first arg, the second arg is assumed to be the locals hash. So, what you're really getting here is:
<%= render "kids/kid_presentation", :locals => { :collection => @kids, :as => :kid } %>
-
Szymon Jeż
- Tag changed from 2.3.2, render to 2.3.2, 3.x, render
I have a similar issue like the one described by ippa.
In my case no variables (locals, objects, collections) passed to render "get" to the partial.
The only variables that "get" to the partial are the instance variables from the controller action and from the template which is calling the partial to render.
I tried for several hours (more than 4) many configurations of the render method. Nothing worked. I even tried to dig in to the Rails source code but failed to find the problem.I'm using Rails 3.0.0beta3 on Ruby 1.8.7p249.
I used:
<%= render :partial => "organization_unit", :collection => @organization_units %> <%= render "organization_unit", {:collection => @organization_units, :as => :organization_unit} %> <%= render @organization_units %> <%= render :partial => 'organization_unit', :locals => {:organization_unit => @organization_unit} %>etc.
And I always get:
NoMethodError in Organization_units#index Showing /app/views/organization_units/_organization_unit.html.erb where line [#2](/projects/8994/tickets/2 "Ticket #2") raised: undefined method `name' for nil:NilClass Extracted source (around line [#2](/projects/8994/tickets/2 "Ticket #2")): 1:
<%= @organization_unit.name %> <%= @organization_unit.email %> -
Szymon Jeż
Huh? Not all of the comment got posted. It seems that the HTML tags caused some trouble.
Hire is the continuation of the above comment:
And I always get:
NoMethodError in Organization_units#index Showing /app/views/organization_units/_organization_unit.html.erb where line [#2](/projects/8994/tickets/2 "Ticket #2") raised: undefined method `name' for nil: NilClass Extracted source (around line [#2](/projects/8994/tickets/2 "Ticket #2")): 1: < tr> 2: < td><%= @organization_unit.name %></ td> 3: < td><%= @organization_unit.email %></ td> Trace of template inclusion: app/views/organization_units/index.html.erb
Only this code works:
<% @organization_units.each do |organization_unit| %> <% @organization_unit = organization_unit%> <%= render "row" %> <% end %>
Any clue?
-
iHiD
Did you try:
<%= render 'organization_unit', :organization_unit => @organization_unit %>and
<% @organization_units.each do |organization_unit| %> <%= render "row", :organization_unit => organization_unit %> <% end %>?
-
Szymon Jeż
Today a checked out Rails 3 RC and plyed with my code, this is working:
and the single organization unit is available as<%= render @organization_units %>organization_unitlocal variable in the partial_organization_unit.html.erb.I tested this code on Rails 3.0.0.beta4 and 3.0.0.beta3 it's working there to... so actually it was my error [embarrassed]. I used
@organization_unitinstead oforganization_unitin the partial (which was the Rails Way in Rails < 3).Sorry for bothering you and IHID - thanks for the suggestion.
-
Dave Schweisguth
This is still a problem. My version:
render 'foo', :object => bar
defined a local named foo with the value of bar in Rails 2.3.11. It does not in Rails 3.0.5. A workaround is
render 'foo', :foo => bar
but this is ever so slightly duplicative. Is this a regression (which is my guess) or an intentional change? If a regression it would be nice to fix it sooner rather than later and remove one bump in the road from Rails 2 to Rails 3.
-
Dave Schweisguth
P.S. On futher consideration it's possible that the warning box in the section of http://guides.rubyonrails.org/layouts_and_rendering.html documenting :object says that the behavior I was using is intentionally not in Rails 3. (I'm uncertain whether "default local variable" refers to the one set by :object.) Confirmation of that welcome.