Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11402 (closed defect: fixed)

Opened 8 months ago

Last modified 8 months ago

[PATCH][TINY] <%= content_for :name %> should not error out or docs are required

Reported by: stephencelis Assigned to: lifofifo
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords:
Cc:

Description

Let's explore an issue with two possible solutions:

<%= yield :title %>       <%# 1. preferred %>
<%= @content_for_title %> <%# 2. not preferred (perhaps even deprecated?), but working %>
<%= content_for :title %> <%# 3. errors out %>

Please note that no. 3 is mentioned in capture_helper.rb:122, so the following patch fixes the content_for method to allow the case. If this is a typo, then we can consider other ways of making things consistent (better docs, for example).

And what about this?

<h1><%= yield :title %></h1>
<%= content_for :title, @title %>

@title is sent to where :title is yielded, but because the ERB tag uses an '=', it's also rendered again at this point. This could be desired behavior, but this could also be confusing to the user who uses <%= content_tag :span, 'content' %> and <% content_tag :span do %>content<% end %> (the case is admittedly quite different, and _IF_ the doubling is desired, it requires a brief explanation in the docs).

So, what's the solution? And docs patch or the patch attached?

I can provide tests if the patched solution is preferred.

Attachments

content_for_should_not_error_out_on_nil.diff (0.7 kB) - added by stephencelis on 03/22/08 16:19:18.
content_for_with_nil.erb (86 bytes) - added by stephencelis on 03/22/08 18:01:06.
fixture for test case (/rails/actionpack/test/fixtures/test/content_for_with_nil.erb)
content_for_should_not_error_out_on_nil_test.diff (1.4 kB) - added by stephencelis on 03/22/08 18:06:10.
Test case (fixture included)

Change History

03/22/08 16:19:18 changed by stephencelis

  • attachment content_for_should_not_error_out_on_nil.diff added.

03/22/08 17:40:09 changed by lifofifo

  • status changed from new to closed.
  • resolution set to invalid.

Please add a failing test case and reopen.

Thanks.

(follow-up: ↓ 3 ) 03/22/08 17:49:28 changed by lifofifo

  • status changed from closed to reopened.
  • resolution deleted.

03/22/08 18:01:06 changed by stephencelis

  • attachment content_for_with_nil.erb added.

fixture for test case (/rails/actionpack/test/fixtures/test/content_for_with_nil.erb)

(in reply to: ↑ 2 ) 03/22/08 18:02:49 changed by stephencelis

  • owner changed from core to lifofifo.
  • status changed from reopened to new.

Replying to lifofifo: Failing test case and fixture attached.

03/22/08 18:06:10 changed by stephencelis

  • attachment content_for_should_not_error_out_on_nil_test.diff added.

Test case (fixture included)

03/28/08 20:03:31 changed by david

  • status changed from new to closed.
  • resolution set to fixed.

(In [9116]) Update doc (closes #11402)