You can already do this in one line:

>
<%= render :partial => "post", :collection => @posts or  
render :partial => "no_post" %>

And soon you'll be able to do:

<%= render @posts or render 'no_post' %>

Which is about as concise as one could want!


On 12-Sep-09, at 6:12 AM, Jeremy Kemper wrote:

>
> On Fri, Sep 11, 2009 at 2:20 PM, rouffj <[email protected]> wrote:
>>
>> Hi,
>>
>> Until now with Rails when we would handle empty collections in apps,
>> we had to code it like that :
>>
>> <%# app/views/posts/index.erb %>
>> <% if @posts.empty? %>
>>  <p>Sorry, there is no posts yet !</p>
>> <% else %>
>>  <% render :partial => "post", :collection => @posts %>
>>
>> <% end %
>>
>> Now with my modest contribution we can handle it in one line in  
>> view :
>>
>> <%# app/views/posts/index.erb %>
>> <%= render :partial => "post", :collection =>
>> @posts, :default_template => "no_post" %>
>>
>> <%# app/views/posts/_no_post.erb %>
>>
>> <p>Sorry, there is no posts yet !</p
>>
>> So we can implement Getting real notion called "The blank slate" more
>> easily.
>>
>> One of you can review my patch (to see if i forget something) or
>> comment it ?
>>
>> Thanks.
>>
>> ---
>> lighthouse ticket : 
>> https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3187
>> patch : 
>> https://rails.lighthouseapp.com/projects/8994/tickets/3187/a/266544/empty_collections_rendering.diff
>
> Hi rouffj,
>
> Nice patch, but I think the option will obfuscate rather than clarify.
>
> Simply using a conditional here is appropriate and clear, not  
> verbose or hard.
>
> Best,
> jeremy
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to