|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I am using ERB templates in my code. It seems too big, can't get my head
around on how to reduce it. I am sure this can be made smaller. My problem is that if there ain't any flash messages than the contained HTML shouldn't be rendered at all. <% if flash[:notice] %> <div class="MessageWrapper"> <span class="Message"> <%= flash[:notice] %> </span> </div> <% end %> <% if flash[:error] %> <div class="MessageWrapper"> <span class="ErrorMessage"> <%= flash[:error] %> </span> </div> <% end %> thanks. -- Posted via http://www.ruby-forum.com/. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
[Note: parts of this message were removed to make it a legal post.]
Hey, If you call your CSS class for a `notice' flash NoticeMessage isntead of just Message, you can make it simple like this: <% flash.each do |k, v| %> <% if v %> <div class="MessageWrapper"> <span class="<%= k.to_s.capitalize %>Message"> <%= v %> </span> </div> <% end %> <% end %> Cheers, Arlen. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Cool, thanks.
The "if v" can be removed, cause if the key exists than there is no problem in rendering its value. Thanks a lot, that was a really quick reply. I just love ruby, cause so much can be expressed in so less. Arlen Cuss wrote: > Hey, > > If you call your CSS class for a `notice' flash NoticeMessage isntead of > just Message, you can make it simple like this: > > <% flash.each do |k, v| %> > <% if v %> > <div class="MessageWrapper"> > <span class="<%= k.to_s.capitalize %>Message"> > <%= v %> > </span> > </div> > <% end %> > <% end %> > > Cheers, > Arlen. -- Posted via http://www.ruby-forum.com/. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
[Note: parts of this message were removed to make it a legal post.]
Hiya, On Fri, Feb 22, 2008 at 2:07 AM, Jigar Gosar <jigar.gosar@gmail.com> wrote: > The "if v" can be removed, cause if the key exists than there is no > problem in rendering its value. Good point, I'm asleep! Thanks a lot, that was a really quick reply. No problems. > I just love ruby, cause so much can be expressed in so less. You're absolutely right. I recently read a good article to this effect:"Do not learn Ruby" http://webmat.wordpress.com/2008/02/...ot-learn-ruby/. It's a fun read. Cheers, Arlen. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
from: http://webmat.wordpress.com/2008/02/...ot-learn-ruby/
"Ruby will get under your skin. You will miss its features and quirks when you’re not using it. You might even find other languages insufferable, once you get comfortable with Ruby. After you’ve started using Ruby, there’s a significant chance you’ll start loathing whatever code base you currently have to work on. Especially if it’s a statically compiled language. A code base you used to think was ok, except for its few quirks." thats exactly what I am experiencing now ![]() thanks for pointing it out. Arlen Cuss wrote: > Hiya, > > On Fri, Feb 22, 2008 at 2:07 AM, Jigar Gosar <jigar.gosar@gmail.com> > wrote: > >> The "if v" can be removed, cause if the key exists than there is no >> problem in rendering its value. > > Good point, I'm asleep! > > Thanks a lot, that was a really quick reply. > > No problems. > > >> I just love ruby, cause so much can be expressed in so less. > > You're absolutely right. I recently read a good article to this> effect: > "Do not learn Ruby" > http://webmat.wordpress.com/2008/02/...ot-learn-ruby/. It's a fun > read. > > Cheers, > Arlen. -- Posted via http://www.ruby-forum.com/. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Feb 21, 2008, at 10:14 AM, Arlen Cuss wrote: > Hiya, > > On Fri, Feb 22, 2008 at 2:07 AM, Jigar Gosar <jigar.gosar@gmail.com> > wrote: > >> The "if v" can be removed, cause if the key exists than there is no >> problem in rendering its value. > > Good point, I'm asleep! > > Thanks a lot, that was a really quick reply. > > No problems. > > >> I just love ruby, cause so much can be expressed in so less. > > You're absolutely right. I recently read a good article to this> effect: > "Do not learn Ruby" > http://webmat.wordpress.com/2008/02/...ot-learn-ruby/. It's a > fun read. > > Cheers, > Arlen. Or put one of these in your application_er (not both, or combine them yourself) (Apologies for the inevitable email wrapping ;-) module Applicationer COLORS = Hash.new('#ff0000').merge!({ :notice => '#00ff00', :warning => '#ff9900', :error => '#ff0000', }) unless const_defined? 'COLORS' # Shows the flash message(s) with a highlight effect def flash_div(*keys) keys.collect { |key| content_tag(:div, flash[key], :id => "#{key}", :class => "flash") if flash[key] }.join + keys.collect { |key| javascript_tag(visual_effect(:highlight, "#{key}", :startcolor => "'#{COLORS[key]}'", :endcolor => "'#ffffff'")) if flash[key] }.join end # Shows the flash message(s), but they go away when clicked. An options hash will be applied to a surrounding div tag. def flash_div(*keys) return '' if keys.blank? options = { :id => 'flash' } options.update(keys.pop) if keys.last.is_a? Hash content_tag(:div, keys.collect { |key| content_tag(:div, flash[key], :id => "#{key}- flash", :class => "#{key} section", nClick => "new Effect.Fade(this);")if flash[key] }.join, options) end end And then in your views (or layout): <%= flash_div :notice, :warning, :error -%> Then toss in some CSS to taste and serve warm. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
thanks this is cool too.
I don't know why, but I don't like generating HTML pragmatically. Maybe the fear came from outputting HTML directly from Servlets as java strings. Ahaa those were the days ![]() Rob Biedenharn wrote: > > Or put one of these in your application_er (not both, or combine > them yourself) (Apologies for the inevitable email wrapping ;-) > -- Posted via http://www.ruby-forum.com/. |
|
![]() |
| Outils de la discussion | |
|
|