joseph rouff
2009-Sep-11 12:26 UTC
#3187 : Handle "blank slate" more easily with render method thanks to :default_template option
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 --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
rouffj
2009-Sep-11 21:20 UTC
#3187 : Handle "blank slate" more easily with render method thanks to :default_template option
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
Jason King
2009-Sep-12 00:05 UTC
Re: #3187 : Handle "blank slate" more easily with render method thanks to :default_template option
I like the concept, not the name. Can I suggest something like: render :partial => "post", :collection => @posts, :if_nil => "no_post" ?? On Sep 11, 2009, at 2:20 PM, rouffj 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 > > >
Adam Hunter
2009-Sep-12 00:06 UTC
Re: #3187 : Handle "blank slate" more easily with render method thanks to :default_template option
The concept is great! Maybe go :if_blank since that''s the check you are running on it. Adam On Sep 11, 2009, at 8:05 PM, Jason King wrote:> > I like the concept, not the name. Can I suggest something like: > > render :partial => "post", :collection => @posts, :if_nil => "no_post" > > ?? > > On Sep 11, 2009, at 2:20 PM, rouffj 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 >> >>> > > > >
Trek Glowacki
2009-Sep-12 02:33 UTC
Re: #3187 : Handle "blank slate" more easily with render method thanks to :default_template option
:if_nil doesn''t describe all cases. The collection could be not nil (e.g. an empty array) and you''d still want the blank slate to show. I''d suggest something related to blankness since it''s the "blank slate" and both [ ].blank? and nil.blank? return true. render :partial => "post", :collection => @posts, :if_blank => "none" -Trek On Fri, Sep 11, 2009 at 8:05 PM, Jason King <smathy.werp@gmail.com> wrote:> > I like the concept, not the name. Can I suggest something like: > > render :partial => "post", :collection => @posts, :if_nil => "no_post" > > ?? > > On Sep 11, 2009, at 2:20 PM, rouffj 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 >> >> > > > > > >
Jeremy Kemper
2009-Sep-12 10:12 UTC
Re: #3187 : Handle "blank slate" more easily with render method thanks to :default_template option
On Fri, Sep 11, 2009 at 2:20 PM, rouffj <rouffj@gmail.com> 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.diffHi 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
rouffj
2009-Sep-12 10:15 UTC
Re: #3187 : Handle "blank slate" more easily with render method thanks to :default_template option
Thanks guys for your suggestions. I Think that i''ll adopt :if_blank option name. Thanks again. Anyone has other ideas ? On Sep 12, 4:33 am, Trek Glowacki <trek.glowa...@gmail.com> wrote:> :if_nil doesn''t describe all cases. The collection could be not nil > (e.g. an empty array) and you''d still want the blank slate to show. > > I''d suggest something related to blankness since it''s the "blank > slate" and both [ ].blank? and nil.blank? return true. > > render :partial => "post", :collection => @posts, :if_blank => "none" > > -Trek > > On Fri, Sep 11, 2009 at 8:05 PM, Jason King <smathy.w...@gmail.com> wrote: > > > I like the concept, not the name. Can I suggest something like: > > > render :partial => "post", :collection => @posts, :if_nil => "no_post" > > > ?? > > > On Sep 11, 2009, at 2:20 PM, rouffj 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/e...
Chris
2009-Sep-13 12:40 UTC
Re: #3187 : Handle "blank slate" more easily with render method thanks to :default_template option
I like the idea of being able to render a collection in one line and I too find it a bit clunky to include the conditional and literal content for the blank condition alongside the 99% case. +1 for :if_blank -Chris On Sep 12, 6:15 am, rouffj <rou...@gmail.com> wrote:> Thanks guys for your suggestions. I Think that i''ll adopt :if_blank > option name. > > Thanks again. > > Anyone has other ideas ? > > On Sep 12, 4:33 am, Trek Glowacki <trek.glowa...@gmail.com> wrote: > > > :if_nil doesn''t describe all cases. The collection could be not nil > > (e.g. an empty array) and you''d still want the blank slate to show. > > > I''d suggest something related to blankness since it''s the "blank > > slate" and both [ ].blank? and nil.blank? return true. > > > render :partial => "post", :collection => @posts, :if_blank => "none" > > > -Trek > > > On Fri, Sep 11, 2009 at 8:05 PM, Jason King <smathy.w...@gmail.com> wrote: > > > > I like the concept, not the name. Can I suggest something like: > > > > render :partial => "post", :collection => @posts, :if_nil => "no_post" > > > > ?? > > > > On Sep 11, 2009, at 2:20 PM, rouffj 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/e... > >
Rodrigo Rosenfeld Rosas
2009-Sep-13 13:39 UTC
Re: #3187 : Handle "blank slate" more easily with render method thanks to :default_template option
I liked the idea. I was just wondering if ":when_blank =>" would not fit a bit better than ":if_blank". Not that it really changes nothing and I would still like the :if_blank option, but just an idea... Em 13-09-2009 12:40, Chris escreveu:> I like the idea of being able to render a collection in one line and I > too find it a bit clunky to include the conditional and literal > content for the blank condition alongside the 99% case. > > +1 for :if_blank > > -Chris > > On Sep 12, 6:15 am, rouffj<rou...@gmail.com> wrote: > >> Thanks guys for your suggestions. I Think that i''ll adopt :if_blank >> option name. >> >> Thanks again. >> >> Anyone has other ideas ? >> >> On Sep 12, 4:33 am, Trek Glowacki<trek.glowa...@gmail.com> wrote: >>...
Mateo Murphy
2009-Sep-13 21:12 UTC
Re: #3187 : Handle "blank slate" more easily with render method thanks to :default_template option
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 <rouffj@gmail.com> 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 > > >
rouffj
2009-Sep-14 10:35 UTC
Re: #3187 : Handle "blank slate" more easily with render method thanks to :default_template option
Mateo Murphy i think that your code proposal is a little bit less clear and more difficult to read. It''s for that i created a patch. *For those who would like this to see this patch integrated to rails could you update the lighthouse ticket with +1.* lighthouse ticket : https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3187 Thanks for your feedbacks. On Sep 13, 11:12 pm, Mateo Murphy <mateo.mur...@gmail.com> wrote:> 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 <rou...@gmail.com> 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/e... > > > 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
Jeremy Kemper
2009-Sep-14 11:33 UTC
Re: #3187 : Handle "blank slate" more easily with render method thanks to :default_template option
Mateo suggests a plain Ruby shorthand since you don''t like the obvious, concise Ruby conditional. Not liking this shorthand is not cause for some even more obscure render option. The ticket was set to "wontfix" already. If you like the feature, please pursue it as a plugin. Best, jeremy On Mon, Sep 14, 2009 at 3:35 AM, rouffj <rouffj@gmail.com> wrote:> > Mateo Murphy i think that your code proposal is a little bit less > clear and more difficult to read. > > It''s for that i created a patch. > > *For those who would like this to see this patch integrated to rails > could you update the lighthouse ticket with +1.* > > lighthouse ticket : https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3187 > > Thanks for your feedbacks. > > On Sep 13, 11:12 pm, Mateo Murphy <mateo.mur...@gmail.com> wrote: >> 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 <rou...@gmail.com> 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/e... >> >> > 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 > > >
rouffj
2009-Sep-14 11:42 UTC
Re: #3187 : Handle "blank slate" more easily with render method thanks to :default_template option
Ok, thanks for all. Sorry if i was a bit persistent. It was my first contribution. I hope that i could help on other tickets on rails core. Subject closed. On Sep 14, 1:33 pm, Jeremy Kemper <jer...@bitsweat.net> wrote:> Mateo suggests a plain Ruby shorthand since you don''t like the > obvious, concise Ruby conditional. Not liking this shorthand is not > cause for some even more obscure render option. > > The ticket was set to "wontfix" already. If you like the feature, > please pursue it as a plugin. > > Best, > jeremy > > On Mon, Sep 14, 2009 at 3:35 AM, rouffj <rou...@gmail.com> wrote: > > > Mateo Murphy i think that your code proposal is a little bit less > > clear and more difficult to read. > > > It''s for that i created a patch. > > > *For those who would like this to see this patch integrated to rails > > could you update the lighthouse ticket with +1.* > > > lighthouse ticket :https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3187 > > > Thanks for your feedbacks. > > > On Sep 13, 11:12 pm, Mateo Murphy <mateo.mur...@gmail.com> wrote: > >> 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 <rou...@gmail.com> 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/e... > > >> > 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