This project is archived and is in readonly mode.
Allow user to specify the partial which will be rendered if the collection is empty or nil
Reported by Prem Sichanugrist (sikachu) | November 20th, 2010 @ 05:02 PM | in 3.x
Hi,
I've think about this a while ago, and it seems like in the real app I've to keep doing this:
<%- unless @posts.empty? %>
<%= render @posts %>
<%- else -%>
<%= render "no_post" %>
<%- end -%>
I think there should be the way to accomplish this better. So, I
propose the :if_empty
option, which user can be
specify the partial name to be rendered if the collection is empty.
So the code portion about could become this:
<%= render :partial => @posts, :if_empty => "no_post" %>
I've also take it further and add support for
:if_empty
and :spacer_template
in the
shorthand version. Those options would be passed in the
locals
hash in the shorthand version, and would only
be use if the first argument is the collection. So, you can do
this
<%= render @posts, :if_empty => "no_post", :spacer_template => "post_spacer" %>
I think this will definitely make the collection render in the
view looks nicer. I've separate the patch into two parts: the first
one with the :if_empty
addition only, and the second
one for shorthand addition. In case you don't like the way I add to
the shorthand, I would love to have at least the first patch got
passed.
I'd love to see this got applied to both master
and
3-0-stable
.
Feedback and suggestion are always welcome. Thanks a lot.
Comments and changes to this ticket
-
José Valim November 25th, 2010 @ 09:47 AM
- State changed from open to invalid
I am closing this mate. Feel free to reopen.
-
Prem Sichanugrist (sikachu) November 25th, 2010 @ 11:03 AM
- State changed from invalid to open
Ok, I've update the patch with the version that we've discussed. It will allow the
spacer_template
to be set in the short-hand version. -
rails February 26th, 2011 @ 12:00 AM
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails February 26th, 2011 @ 12:00 AM
- State changed from open to stale
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>