This project is archived and is in readonly mode.

#4620 ✓invalid
Craig Buchek

partial locals do not accept a string constant

Reported by Craig Buchek | May 16th, 2010 @ 08:05 PM

When I try to set a locals variable to a string in a partial render, it doesn't get assigned properly. If I instead use an intermediate variable, it works.

View file: <%= render :partial => 'partial', :locals => {:who => 'me'} %>

Partial file: <%= @who %>

Result: empty string

Expected result: 'me'

Work-around view file: <% @who => 'me' %><%= render :partial => 'partial', :locals => {:who => @who} %>

The ActionView::Partials docs don't mention that the targets have to be variables, but that appears to be the case.

The ActionController::Base docs show an example using a string: render :partial => "person", :locals => { :name => "david" }

Comments and changes to this ticket

  • Matt Jones

    Matt Jones May 16th, 2010 @ 10:06 PM

    • State changed from “new” to “invalid”

    Did you happen to notice whilst reading the ActionView::Base docs that :locals are passed as local variables (no sigil) rather than instance variables (@ sigil)?

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages