You are here: Forums Ask a Rails expert bold flash[:notice]...
Posted in Forums : Ask a Rails expert
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! |
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; |
Authority 25
Posting Rating 90
Sign in to rate this post
|
Sorry, I didn’t escape my code <div id="notice"><%= flash[:notice] %></div> |
Authority 62
Posting Rating 86
Sign in to rate this post
|
Or use something like Stickies. |
Authority 12
Posting Rating 0
Sign in to rate this post
|
Can you actually put divs in the controller? |
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. |
Authority 12
Posting Rating 15
Sign in to rate this post
|
i’m afraid flash[:notice] is already deprecated in rails latest version |
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 |
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 |
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 |
Authority 12
Posting Rating 91
Sign in to rate this post
|
application.rhtml: stylesheet.css:
:) |
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
<% [: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;
}
|
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