Installation
Add this line to your application's Gemfile:
gem 'uploadify_rails'
And then execute:
$ bundle
Usage
Migration (Photo work with Paperclip):
create_table :photos do |t|
t.integer :advert_id # объявление
t.integer :user_id # пользователь (авторизованный)
t.string :session_id # пользователь (гость)
t.string :data_content_type
t.string :data_file_name
t.integer :data_file_size
t.timestamps
end
Routes:
resources :photos, :only => [:create]
post "/photo/:id" => "photos#destroy"
Javascripts:
//= require uploadify
Stylesheets:
*= require uploadify
Model Parent (F.E. Advert):
class Advert ...
...
has_many :photos, :dependent => :destroy
accepts_nested_attributes_for :photos, :allow_destroy => true
...
# Support only one relation name in just moment
uploadify_nested_parent :relations => [:photos]
...
Model with Photo:
class Photo ...
uploadify_nested_resource
Photos Controller:
class PhotosController < ApplicationController
uploadify_nested_resource
end
Adverts Controller:
class AdvertsController < ApplicationController
...
def create
@advert = Advert.new
@advert.build_attributes_from_params(params, current_user, session[:session_id])
if @advert.save
...
View:
Example: in app/views/shared/uploadify/...
Formtastic Form Integration (@advert form):
= form.input :photos, :as => :uploadify
Enjoy!
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Thanks
Thanks to https://github.com/dead-zygote for javascripts and first time realization