redde 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -47,6 +47,26 @@ Add `admin.scss` and `admin.js` to assets precompilation in config/production.rb
47
47
  ## Добавление фотографий
48
48
 
49
49
  rails g redde:photo
50
+
51
+ Добавьте в routes.rb единожды
52
+
53
+ concern :imageable do
54
+ resources :photos, only: [:show, :create, :destroy] do
55
+ post 'sort', :on => :collection
56
+ end
57
+ end
58
+
59
+ и для каждой модели роуты `concerns :imageable` к которой необходимо добавить фотографии, например для Product
60
+
61
+ namespace :admin do
62
+ resources :products do
63
+ concerns :imageable
64
+ end
65
+ end
66
+
67
+ Не забудьте добавить полиморфную связь
68
+
69
+ has_many :photos, dependent: :destroy, as: :imageable
50
70
 
51
71
  создаст scaffold для модели Photo с полиморфной связью
52
72
 
@@ -11,20 +11,19 @@ class Admin::PhotosController < ActionController::Base
11
11
 
12
12
  def create
13
13
  if params[:product_id].present?
14
- @product = Product.find(params[:product_id])
15
- @photo = @product.photos.build(src: params[:file])
14
+ parent = Product.find(params[:product_id])
16
15
  end
17
- if @photo.save
18
- render layout: false
19
- else
16
+ @photo = parent.photos.build(src: params[:file])
17
+ unless @photo.save
20
18
  render js: 'alert("Ошибка! Фото не загружено")'
21
19
  end
22
20
  end
23
21
 
24
22
  def destroy
25
23
  @photo = Photo.find(params[:id])
26
- @photo.destroy
27
- render 'admin/photos/destroy'
24
+ if @photo.destroy
25
+ render 'admin/photos/destroy'
26
+ end
28
27
  end
29
28
 
30
29
  end
@@ -2,4 +2,4 @@
2
2
  = link_to photo.src.url do
3
3
  = image_tag photo.src.admin
4
4
  %em= photo.src.to_s.gsub(/.*\/(.*)\z/,'\1')
5
- = link_to "удалить", url_for([:admin,parent,photo]), :method => :delete, :confirm => "Точно удалить?", :remote => true, :title => "Удалить", :class => "del"
5
+ = link_to "удалить", url_for([:admin, photo.imageable, photo]), :method => :delete, :confirm => "Точно удалить?", :remote => true, :title => "Удалить", :class => "del"
@@ -1,12 +1,12 @@
1
1
  - unless parent.new_record?
2
- =content_for(:page_sidebar) do
2
+ = content_for(:page_sidebar) do
3
3
  %h5
4
4
  Фотографии
5
5
  - if editable ||= false
6
- = link_to "ред.", [:admin,parent]
6
+ = link_to "ред.", [:admin, parent]
7
7
  .product-photos
8
8
  %ul.photos#photo-list
9
- = render :partial => "admin/photos/photo", :collection => eval("parent.#{photos.to_s}"), :as => :photo, :locals => {:parent => parent}
9
+ = render parent.photos
10
10
 
11
11
  #preview
12
12
  #drag-n-drop{:style => "display: none; margin-top: 5px;"}
@@ -19,4 +19,4 @@
19
19
  .b-button.js-fileapi-wrapper
20
20
  .b-button__text Загрузить файлы
21
21
  %input.b-button__input.js-fileapi{:name => "files", :type => "file", :multiple => true, data: {"upload-url" => url_for([:admin, parent, :photos])}}
22
- = photo_sortable url_for([:sort,:admin,parent,photos])
22
+ = photo_sortable url_for([:sort, :admin, parent, :photos])
data/lib/redde/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Redde
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -28,7 +28,7 @@ describe Redde::Generators::LayoutGenerator do
28
28
 
29
29
  # check js and css
30
30
  assert_file "app/assets/javascripts/admin.js"
31
- assert_file "app/assets/stylesheets/admin.scss"
31
+ assert_file "app/assets/stylesheets/admin/index.scss"
32
32
 
33
33
  #check images
34
34
  assert_directory "app/assets/images/admin"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redde
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-02-13 00:00:00.000000000 Z
13
+ date: 2014-02-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jquery-rails
@@ -329,7 +329,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
329
329
  version: '0'
330
330
  segments:
331
331
  - 0
332
- hash: 875708741128439050
332
+ hash: 1230283241805079294
333
333
  required_rubygems_version: !ruby/object:Gem::Requirement
334
334
  none: false
335
335
  requirements:
@@ -338,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
338
338
  version: '0'
339
339
  segments:
340
340
  - 0
341
- hash: 875708741128439050
341
+ hash: 1230283241805079294
342
342
  requirements: []
343
343
  rubyforge_project:
344
344
  rubygems_version: 1.8.24