Skip to content

Commit

Permalink
added attachment support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Dickey committed Dec 5, 2011
1 parent eba1e41 commit 69d7283
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,5 +3,6 @@ log/*.log
pkg/
test/dummy/db/*.sqlite3
test/dummy/log/*.log
test/dummy/public/uploads
test/dummy/tmp/
.sass-cache
3 changes: 2 additions & 1 deletion Gemfile
Expand Up @@ -5,7 +5,8 @@ gemspec
gem 'haml'
gem 'devise'
gem 'simple_form'
gem 'mailboxer'
gem 'mailboxer', git: 'git://github.com/dickeytk/mailboxer'
gem 'carrierwave'
gem "jquery-rails"
gem 'coffee-rails'
gem 'sass-rails'
Expand Down
19 changes: 14 additions & 5 deletions Gemfile.lock
@@ -1,3 +1,12 @@
GIT
remote: git://github.com/dickeytk/mailboxer
revision: 18b7aad4ac06265c952a30f212db6ead1c8cc94a
specs:
mailboxer (0.5.4)
carrierwave (>= 0.5.8)
foreigner (>= 0.9.1)
rails (>= 3.1.0)

PATH
remote: .
specs:
Expand Down Expand Up @@ -38,6 +47,8 @@ GEM
arel (2.2.1)
bcrypt-ruby (3.0.1)
builder (3.0.0)
carrierwave (0.5.8)
activesupport (~> 3.0)
coffee-rails (3.1.1)
coffee-script (>= 2.2.0)
railties (~> 3.1.0)
Expand Down Expand Up @@ -65,9 +76,6 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mailboxer (0.5.4)
foreigner (>= 0.9.1)
rails (>= 3.1.0)
mime-types (1.17.2)
multi_json (1.0.4)
orm_adapter (0.0.5)
Expand Down Expand Up @@ -112,7 +120,7 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.4)
sqlite3 (1.3.5)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
Expand All @@ -126,11 +134,12 @@ PLATFORMS
ruby

DEPENDENCIES
carrierwave
coffee-rails
devise
haml
jquery-rails
mailboxer
mailboxer!
messaging!
sass-rails
simple_form
Expand Down
29 changes: 28 additions & 1 deletion README → README.md
Expand Up @@ -7,4 +7,31 @@ Overview of features:
- Compose new message with: multiple receivers, multiple attachments. If this is a reply, quote the replied message.
- Message view (1 message only, no threading gmail style), options to download attachment and delete the message.

This Messaging System also exists as a Refinery CMS engine, see https://github.com/frodefi/refinerycms-messaging.
This Messaging System also exists as a Refinery CMS engine, see https://github.com/frodefi/refinerycms-messaging.

Running the demo app
====================

To run the demo app, first clone the repo

````
$ git clone git@github.com:frodefi/rails-messaging.git
````

Install gems from project root

````
bundle
````

From the dummy app (./test/dummy), create the database

````
$ rake db:migrate
````

Start the server!

````
$ rails server
````
3 changes: 0 additions & 3 deletions README.rdoc

This file was deleted.

8 changes: 6 additions & 2 deletions app/assets/stylesheets/messaging/messages.sass
Expand Up @@ -45,14 +45,14 @@ header
box-shadow: 0 0 7px black

nav
margin: 9px 0
> a
display: block
margin: 9px 0 10px 0
margin: 1px 0
text-align: left
padding: 10px
vertical-align: middle
display: block
padding: 10px
font-weight: bold
&:hover
background-color: #eee
Expand Down Expand Up @@ -188,6 +188,10 @@ textarea
clear: both
padding: 20px 0
line-height: 1.4
.attachment
margin: 10px 0
.attachment:before
content: 'Attachment: '

#compose
margin: 55px 0
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/messaging/messages_controller.rb
Expand Up @@ -20,12 +20,12 @@ def create
flash[:alert] = "You do not have permission to view that conversation."
return redirect_to root_path
end
receipt = current_user.reply_to_conversation(@conversation, @message.body)
receipt = current_user.reply_to_conversation(@conversation, @message.body, nil, true, true, @message.attachment)
else
unless @message.valid?
return render :new
end
receipt = current_user.send_message(@message.recipients, @message.body, @message.subject)
receipt = current_user.send_message(@message.recipients, @message.body, @message.subject, true, @message.attachment)
end
flash[:notice] = "Message sent."

Expand Down
2 changes: 1 addition & 1 deletion app/models/messaging/message.rb
Expand Up @@ -4,7 +4,7 @@ class Message
include ActiveModel::Conversion
extend ActiveModel::Naming

attr_accessor :recipients, :subject, :body, :conversation_id
attr_accessor :recipients, :subject, :body, :conversation_id, :attachment

validates :recipients, presence: true
validates :subject, presence: true
Expand Down
1 change: 1 addition & 0 deletions app/views/messaging/messages/new.html.haml
Expand Up @@ -7,4 +7,5 @@
= f.input_field :subject
= f.label :body, required: false
= f.input_field :body, as: :text
= f.input :attachment, as: :file
= f.button :submit, 'Send message'
4 changes: 4 additions & 0 deletions app/views/messaging/messages/show.html.haml
Expand Up @@ -11,9 +11,13 @@
.from= message.sender
.date #{message.created_at.to_s(:long)} (#{time_ago_in_words(message.created_at)} ago)
.body= message.body
- if message.attachment.url
.attachment
= link_to message.attachment_identifier, message.attachment.url
#reply
= simple_form_for @message do |f|
= f.input :conversation_id, as: :hidden
= f.label :body, label: 'Reply', required: false
= f.input_field :body, as: :text, label: 'Reply'
= f.input :attachment, as: :file
= f.button :submit, 'Reply to conversation'
5 changes: 5 additions & 0 deletions test/dummy/db/migrate/20111205020919_add_attachments.rb
@@ -0,0 +1,5 @@
class AddAttachments < ActiveRecord::Migration
def change
add_column :notifications, :attachment, :string
end
end
3 changes: 2 additions & 1 deletion test/dummy/db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20111204042611) do
ActiveRecord::Schema.define(:version => 20111205020919) do

create_table "conversations", :force => true do |t|
t.string "subject", :default => ""
Expand All @@ -32,6 +32,7 @@
t.integer "notified_object_id"
t.string "notified_object_type"
t.string "notification_code"
t.string "attachment"
end

add_index "notifications", ["conversation_id"], :name => "index_notifications_on_conversation_id"
Expand Down

0 comments on commit 69d7283

Please sign in to comment.