Code Monkey home page Code Monkey logo

the_notification's Introduction

TheNotification

Just add JSON on HTML notifications in your APP

Designed for Bootstrap 3 style of for toastr notifications

How it works

Just remove

<%= form_for(@resource) do |f| %>
  <% if @resource.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@resource.errors.count, "error") %> prohibited this resource from being saved:</h2>

      <ul>
      <% @resource.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  # ....

<% end %>

with

<%= form_for(@post) do |f| %>
  <%= render partial: 'the_notification/form', locals: { object: @post } %>

  # ....

<% end %>

and add to Layout

<body>    
  <%= render partial: 'the_notification/flash' %>
  <%= yield %>

application.css

*= require bootstrap
*= require the_notification/vendors/toastr

application.js

//= require the_notification/vendors/toastr
//= require the_notification

$ ->
  TheNotification.show_notifications()

HTML or JSON

<%= render partial: 'the_notification/flash', locals: { format: :html } %>
<%= render partial: 'the_notification/form', locals: { object: @post, format: :html } %>

or

<%= render partial: 'the_notification/flash', locals: { format: :json } %>
<%= render partial: 'the_notification/form', locals: { object: @post, format: :json } %>

initializers/the_notification.rb

TheNotification.configure do |config|
  config.default_type = :json # :html
end

Localized errors

models/user.rb

class Post < ActiveRecord::Base
  include TheNotification::LocalizedErrors
end

config/locales/ru.yml

activerecord:
  models:
    post: Публикация
  attributes:
    post:
      title: "Загловок"

Now errors messages will looks like this:

Загловок: не может быть пустым

instead

Title: не может быть пустым

Installation

gem 'the_notification'
$ bundle

Usage

TODO: Write usage instructions here

the_notification's People

Contributors

the-teacher avatar

Stargazers

Alexey Bezrukov avatar

Watchers

 avatar James Cloos avatar

the_notification's Issues

Inline errors

  # @post.inline_localized_errors(except: [:'comment.title'])
  def inline_localized_errors opts = {}
    opts.symbolize_keys!
    excepts = opts.delete(:except) || []

    errors.inject({}) do |hash, (k, v)|
      unless excepts.include?(k.to_sym)
        name = self.class.human_attribute_name k
        key  = "#{ self.class }/#{ k }".parameterize.underscore.camelcase

        hash[key]       = {} if hash[key].blank?
        hash[key][name] = [] if hash[key][name].blank?
        hash[key][name].push v
      end

      hash
    end
  end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.