Add documentation for local_assigns [ci skip] #18970

Merged
merged 1 commit into from Feb 18, 2015

Projects

None yet

6 participants

@nithinbekal
Contributor

When passing local variables to sub-templates, the variables can be accesses using local_assigns. This part of the documentation was removed in the commit 3dfcae6.

In earlier versions, defined? foo did not work reliably, so local_assigns was the recommended way to check if a local variable has beed defined. Now defined? works, and can be used safely, but local_assigns is still available and useful in some scenarios, such as:

Headline: <%= defined?(headline) ? headline : '' %>
Headline: <%= local_assigns[:headlines] %>

This was also brought up by @dhh in another issue today: #18962. It's especially confusing since the only mention of local_assigns was removed from the documentation even though the feature is still available. I've written up more about this here.

@cristianbica
Contributor

There's another PR on the same topic #15700

@arthurnn arthurnn added the docs label Feb 17, 2015
@egilburg
Contributor

👍, instead of if defined(some_flag) && some_flag, I can do if local_assigns[:some_flag]

@rafaelfranca rafaelfranca merged commit 3e66017 into rails:master Feb 18, 2015
@rohandaxini
Contributor

good to see this is merged 👍

@weiqingtoh weiqingtoh referenced this pull request in Coursemology/coursemology2 Oct 17, 2016
Merged

Implement submit for publishing #1591

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment