Rails how to create Jquery flash message instead of the default rails message?

Groupon-style notification put background with alfa-channel for best look.

Groupon-style notification put background with alfa-channel for best look #rails controller flash:notice = "Login successful! " #rails helper module ApplicationHelper def flash_notifications message = flash:error || flash:notice if message type = flash. Keys0.

To_s %Q{$. Notification({ message:"#{message}", type:"#{type}" });} end end end #rails layout #javascript code (function( $, undefined ) { $. Notification = function(options) { var opts = $.

Extend({}, {type: 'notice', time: 3000}, options); var o = opts; timeout = setTimeout('$.notification.removebar()', o. Time); var message_span = $(''). AddClass('jbar-content').

Html(o. Message); var wrap_bar = $(''). AddClass('jbar jbar-top').

Css("cursor", "pointer"); if (o. Type == 'error') { wrap_bar. Css({"color": "#D8000C"}) }; wrap_bar.

Click(function(){ $.notification.removebar() }); wrap_bar. Append(message_span).hide() . InsertBefore($('.

Container')). FadeIn('fast'); }; var timeout; $.notification. Removebar = function(txt) { if($('.

Jbar'). Length){ clearTimeout(timeout); $('. Jbar').

FadeOut('fast',function(){ $(this).remove(); }); } }; })(jQuery); #css . Jbar{ height:50px; width:100%; position:fixed; text-align:center; left:0px; z-index:9999999; margin:0px; padding:0px; filter:progid:DXImageTransform.Microsoft. Alpha(opacity=92); opacity: 0.92; -moz-opacity: 0.92; -moz-box-shadow: #555 0px 0px 5px; box-shadow: #555 0px 0px 5px; } .

Jbar-top{ top:0px; } . Jbar-bottom{ bottom:0px; } . Jbar-content{ line-height:46px; font-size: 18px; } .

Jbar-top a. Jbar-cross{ top:8px; } . Jbar-bottom a.

Jbar-cross{ bottom:8px; }.

It kind of depends on what you mean by a custom JQuery message. If for example you have a partial that takes a message and renders it in some way, then you might have something like "path_to_success_partial", :locals => {:message => flash:message} %> "path_to_error_partial", :locals => {:message => flash:message} %> BRUGERNAVN: | UPVOTES: | DOWN VOTES: OPRETTET: 'Are you sure? ', :method => :delete %> and then in your partials you can have something like Mind you, if you want to use flash messages in your application, you should always put them in a partial somewhere and stick it in your application wide view in layouts/application.html.

Erb so you can generalize the functionality.

(Where I have my flash message helper – Rails beginner Jun 28 at 17:53 You can put that if statement where ever you want, I just assumed you want it up top. – vinceh Jun 28 at 18:12 I want the error message to appear right beside the vote up link. Instead of having it in the top.

– Rails beginner Jun 28 at 18:27 You have the 'vote up' button displayed for all posts, so wouldn't there be a bunch of them on the page? – Chris Barretto Jun 28 at 19:02 Like I said before, you can stick that if statement anywhere you like, if you want it to be right beside your Vote up link, then you can put it there. – vinceh Jun 28 at 19:15.

You can get the flash message in the view using flash:notice or flash:error and you use to display it in whichever you like. For instance.

I am already using that flash message. Instead of the rails default flash message. I want to create a Jquery flash message that appears near the vote_up link – Rails beginner Jun 28 at 17:03.

If you want something like this. Than you can use this gem.

I mean something like this: amino. Dk/buzz/Forside try to upvote a post – Rails beginner Jul 18 at 16:35 It is a really nice gem, would be great if the doc was also available on english – Rails beginner Jul 18 at 16:38.

I think you will struggle to get an elegent solution using redirect_to root_path. Assuming your root_path controller action is in the same controller as vote_up, I'd do something like this: # Assuming your root_path points to index def index @posts = Post. All end def vote_up # You'll need to set up all the prerequisites for your index view here @posts = Post.

All @post = @posts. Detect {|post| post. Id == params:id} begin current_user.

Up_vote(@post) redirect_to(root_url, :notice => 'Tak for dit indlæg, det er nu online! ') rescue MakeVoteable::Exceptions::AlreadyVotedError @post.errors. Add_to_base("Already voted!") render 'index' end end Then make your view something like this: ... Then use CSS to style div.

Posterror, and / or jQuery to do some fancy effects, one of the many jQuery tooltip plugins would be a good head start to this. Best of all would be to make vote_up AJAX.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions