New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for local_assigns [ci skip] #18970

Merged
merged 1 commit into from Feb 18, 2015

Conversation

Projects
None yet
6 participants
@nithinbekal
Contributor

nithinbekal commented Feb 17, 2015

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

This comment has been minimized.

Show comment
Hide comment
@cristianbica

cristianbica Feb 17, 2015

Member

There's another PR on the same topic #15700

Member

cristianbica commented Feb 17, 2015

There's another PR on the same topic #15700

@egilburg

This comment has been minimized.

Show comment
Hide comment
@egilburg

egilburg Feb 17, 2015

Contributor

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

Contributor

egilburg commented Feb 17, 2015

👍, 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

rafaelfranca added a commit that referenced this pull request Feb 18, 2015

Merge pull request #18970 from nithinbekal/local-assigns-doc
Add documentation for local_assigns [ci skip]
@rohandaxini

This comment has been minimized.

Show comment
Hide comment
@rohandaxini

rohandaxini Mar 28, 2015

Contributor

good to see this is merged 👍

Contributor

rohandaxini commented Mar 28, 2015

good to see this is merged 👍

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