Chatty
Install
First bundle it in your Gemfile:
gem "chatty"
Execute bundle install
.
Throw something like this in your application.js.coffee
:
#= require chatty
Trow this in your ApplicationHelper
:
class ApplicationHelper
include Chatty::ChatsHelper
end
Add abilities for who can create and access chats through CanCan:
class Ability
include CanCan::Ability
def initialize(user)
if user
can :show, Chatty::Chat
can [:new, :create], Chatty::Message
can [:edit, :update], Chatty::Message do |message|
if message.user == user
true
else
false
end
end
if user.email == "admin@example.com"
can :manage, Chatty::Chat
can :manage, Chatty::Message
end
end
end
end
Usage
Create a chat somewhere in your code:
chat = Chatty::Chat.new(:user => current_user)
Show that same chat in a view:
<%= chatty_chat(@chat) %>
Try to view that chat with the user that got attached and with an admin in another window. Now start chatting!
Inspect the HTML to style that shit yourself!