Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert bold flash[:notice]...

Replytotopic

bold flash[:notice]

Posted in Forums : Ask a Rails expert

 
Profile

Authority 12
Posting Rating 0
Sign in to rate this post

I am trying to figure out how to make the flash[:notice] bold and if there is any way I can set other CSS styles on it as well.

Thanks!

 
Me

Authority 25
Posting Rating 90
Sign in to rate this post

Display your notice inside an html element like this.

<%= flash[:notice] %>

Then style the element with css how ever you like. #notice { font-weight: bold;
}

 
Me

Authority 25
Posting Rating 90
Sign in to rate this post

Sorry, I didn’t escape my code

<div id="notice"><%= flash[:notice] %></div>
 
Pjones

Authority 62
Posting Rating 86
Sign in to rate this post

Or use something like Stickies.

 
Profile

Authority 12
Posting Rating 0
Sign in to rate this post

Can you actually put divs in the controller?

 
Profile

Authority 12
Posting Rating 99
Sign in to rate this post

No, that’s View code. It’s largely frowned upon to put any view code in the controller. However, you will want to set the flash value in the controller.

I have to second Chris Barnes and recommend you use a CSS style to control the appearance of the tag.

 
Profile

Authority 12
Posting Rating 15
Sign in to rate this post

i’m afraid flash[:notice] is already deprecated in rails latest version

 
Me

Authority 37
Posting Rating 95
Sign in to rate this post

Why should flash[:notice] be deprecated? flash is basically just a Hash where you can store any kind of data for exactly one request. It just so happens that most people always used flash[:notice], flash[:error] and what not … It could also be flash[:foo] or flash[:info_message].

@topic: Just like the others said – wrap any HTML object around your flash[:notice] (p, div, span or whatever) and style it accordingly using CSS. You could, of course, also do something like flash[:notice] = “Record saved!” in your controller – but obviously, that’s not good MVC there! ;)

Cheers

 
Profile

Authority 12
Posting Rating 15
Sign in to rate this post

yes, my mistake what i mean is flash declared as instance variable already deprecated. Others can be referred here :http://www.rubyonrails.org/deprecation
:)

 
Pic

Authority 25
Posting Rating 70
Sign in to rate this post

to clarify for anyone still confused, @flash[:whatever] is deprecated, flash[:whatever] works as expected

 
Working_with_rails

Authority 12
Posting Rating 91
Sign in to rate this post

application.rhtml:


    <% flash.each do |type,content| %>   
      <%# special flashes we don't want to show:  %>
      <% next if [:foo, :bar, :search].include?(type) %>
      <%= content_tag(:div, content, :id => "flash_"+type.to_s) -%> <br/>                 
    <% end -%>


stylesheet.css:


#flash_error {
    border: 2px solid #8B0000;
    padding:10px;
    background-color:#CD5C5C;
    color:gold;
    font-weight:bold;
}

#flash_notice {
    border: 1px solid green;    
    padding:10px;    
    background-color:#3CB371;
    color:#FFFF00;
    font-weight:bold;
}

:)

 
Bluemtns

Authority 50
Posting Rating 97
Sign in to rate this post

I agree with Chris and Marcin – but tend to take it further. I set up a shared template for flashes under shared/_flash.rhtml
Then you can add appropriate styling for each flash type – if there’s one present. Generally something along the lines of Marcin’s example thus:

<% [:error, :warning, :notice].each do |level|
    if flash[level] -%>
      <div class="flash <%= level.to_s -%>"><%= flash[level].join('\n') -%></div>
  <% end -%>
<% end -%>

Then add the following to your stylesheet:

 .flash {
   font-weight: bold;
   padding: 5px;
   margin-bottom: 5px;
 }
.error {
   background-color: #FAA;
   border: solid 2px red;
 }
 .warning {
   background-color: #FFA;
   border: solid 2px yellow;
 }
 .notice {
   background-color: #AFA;
   border: solid 2px green;
 }

Replytotopic

Other Recent Topics

Ask a Rails expert : FILE EDIT/DELETE

Ask a Rails expert : decrypting the password

Ask a Rails expert : Static Objects in Rails

Ask a Rails expert : Newbie - Rake Cant Execute Test

Ask a Rails expert : Call Web service

Ask a Rails expert : RMagick issues

Ask a Rails expert : [NewBie] Ask About ActiveRecord::Base.transaction

Ask a Rails expert : Barcode detection in rails app

Ask a Rails expert : how to get the stat code from the header of repsonse

Ask a Rails expert : Live validation

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel