Kontextsensitive Benachrichtigungen für Rails && xhr.
gem install 'crouton'
Erfordern Sie einfach crouton in Ihrem JavaScript und CSS:
//= require crouton @import ' crouton ' ; Verwenden Sie dann die Methode render_crouton in Ihren Controllern. Jede Option, die Sie übergeben, wird in eine Nachricht konvertiert.
class PostsController < ActionController :: Base
def update
if @post . save
render_crouton notice : 'Saved'
else
render_crouton errors : @post . errors
end
end
end Finden Sie schließlich einen guten Platz in Ihrem HTML für den Crouton und fügen Sie die CSS-Klasse .crouton-placeholder in den Container der Wahl hinzu.
< div class =" content crouton-placeholder " >
...Drei Stile werden aus der Schachtel unterstützt: Info , Warnung und Gefahr . Die Dauer jeder Nachricht beträgt 1500, 2000 bzw. 3000.
Sie können die Farben für diese drei Stile anpassen, indem Sie die folgenden SASS -Variablen definieren:
$crouton-info$crouton-warning$crouton-dangerSie können auch Ihre benutzerdefinierten Nachrichten erstellen:
render_crouton Crouton :: Message . new ( :hint , 'You can double tap for more info.' , duration : 5000 ) , placeholder : '.custom-crouton-placeholder' Copyright (c) 2014 Máximo Mussini
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Der Name und die Idee von Crouton stammen aus einem Blog -Artikel von Cyril Mottier.