dust-generators 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dust/version.rb +1 -1
- data/lib/generators/dust/albums/albums_generator.rb +129 -34
- data/lib/generators/dust/albums/templates/app/controllers/albums_controller.rb +24 -18
- data/lib/generators/dust/albums/templates/app/controllers/photos_controller.rb +37 -40
- data/lib/generators/dust/albums/templates/app/controllers/view_albums_controller.rb +6 -7
- data/lib/generators/dust/albums/templates/app/helpers/albums_helper.rb +1 -1
- data/lib/generators/dust/albums/templates/app/helpers/photos_helper.rb +1 -1
- data/lib/generators/dust/albums/templates/app/helpers/view_albums_helper.rb +1 -1
- data/lib/generators/dust/albums/templates/app/models/album.rb +8 -4
- data/lib/generators/dust/albums/templates/app/models/photo.rb +11 -4
- data/lib/generators/dust/albums/templates/app/views/albums/_form.html.erb +48 -18
- data/lib/generators/dust/albums/templates/app/views/albums/_search.html.erb +4 -4
- data/lib/generators/dust/albums/templates/app/views/albums/_upload_script.html.erb +11 -11
- data/lib/generators/dust/albums/templates/app/views/albums/edit.html.erb +3 -3
- data/lib/generators/dust/albums/templates/app/views/albums/index.html.erb +23 -23
- data/lib/generators/dust/albums/templates/app/views/albums/manage.html.erb +65 -0
- data/lib/generators/dust/albums/templates/app/views/albums/new.html.erb +3 -3
- data/lib/generators/dust/albums/templates/app/views/albums/show.html.erb +33 -21
- data/lib/generators/dust/albums/templates/app/views/albums/show.js.erb +1 -0
- data/lib/generators/dust/albums/templates/app/views/photos/_form.html.erb +20 -19
- data/lib/generators/dust/albums/templates/app/views/photos/_photo.html.erb +25 -23
- data/lib/generators/dust/albums/templates/app/views/photos/_search.html.erb +6 -0
- data/lib/generators/dust/albums/templates/app/views/photos/array.js.erb +3 -0
- data/lib/generators/dust/albums/templates/app/views/photos/edit.html.erb +6 -6
- data/lib/generators/dust/albums/templates/app/views/photos/index.html.erb +28 -23
- data/lib/generators/dust/albums/templates/app/views/photos/new.html.erb +4 -4
- data/lib/generators/dust/albums/templates/app/views/photos/show.html.erb +9 -9
- data/lib/generators/dust/albums/templates/app/views/photos/show.js.erb +2 -2
- data/lib/generators/dust/albums/templates/app/views/view_albums/index.html.erb +25 -14
- data/lib/generators/dust/albums/templates/app/views/view_albums/show.html.erb +23 -12
- data/lib/generators/dust/albums/templates/images/save_position.png +0 -0
- data/lib/generators/dust/albums/templates/javascripts/dragsort.js +288 -0
- data/lib/generators/dust/albums/templates/javascripts/dust_album.js +28 -0
- data/lib/generators/dust/albums/templates/{uploadify → javascripts/uploadify}/jquery.uploadify.v2.1.0.js +0 -0
- data/lib/generators/dust/albums/templates/{uploadify → javascripts/uploadify}/swfobject.js +0 -0
- data/lib/generators/dust/albums/templates/{uploadify → javascripts/uploadify}/uploadify.swf +0 -0
- data/lib/generators/dust/albums/templates/migration/albums_migration.rb +39 -0
- data/lib/generators/dust/albums/templates/stylesheets/dust_album.css +16 -0
- data/lib/generators/dust/albums/templates/stylesheets/dust_album_app.css +15 -0
- data/lib/generators/dust/albums/templates/{uploadify.css → stylesheets/uploadify.css} +1 -1
- data/rails_generators/dust_albums/templates/app/controllers/view_albums_controller.rb +1 -1
- data/rails_generators/dust_albums/templates/app/views/albums/show.html.erb +1 -1
- metadata +17 -12
- data/lib/generators/dust/albums/templates/albums_migration.rb +0 -18
- data/lib/generators/dust/albums/templates/dust_album.css +0 -11
- data/lib/generators/dust/albums/templates/jquery-1.4.2.js +0 -6240
- data/lib/generators/dust/albums/templates/photos_migration.rb +0 -20
data/lib/dust/version.rb
CHANGED
@@ -1,58 +1,153 @@
|
|
1
|
-
require '
|
1
|
+
require 'generators/dust'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'rails/generators/generated_attribute'
|
2
4
|
|
3
5
|
module Dust
|
4
6
|
module Generators
|
5
|
-
class AlbumsGenerator <
|
7
|
+
class AlbumsGenerator < Base
|
8
|
+
include Rails::Generators::Migration
|
6
9
|
desc "Create all migrations and copy all files for Dust Albums."
|
7
|
-
|
8
|
-
|
10
|
+
|
11
|
+
argument :parent_model_name, :type => :string, :required => true, :banner => 'ParentModelName'
|
12
|
+
argument :child_model_name, :type => :string, :required => true, :banner => 'ChildModelName'
|
13
|
+
|
14
|
+
def source_root
|
9
15
|
@source_root ||= File.expand_path('../templates', __FILE__)
|
10
16
|
end
|
11
17
|
|
12
18
|
def create_migration
|
13
|
-
|
14
|
-
route("resources :photos")
|
15
|
-
migration_template "albums_migration.rb", "db/migrate/create_albums.rb"
|
16
|
-
migration_template "photos_migration.rb", "db/migrate/create_photos.rb"
|
19
|
+
migration_template "migration/albums_migration.rb", "db/migrate/create_#{parent_plural_name}.rb"
|
17
20
|
end
|
21
|
+
|
22
|
+
def routes
|
23
|
+
route("match \"all/#{parent_plural_name}\" => \"view_#{parent_plural_name}#index\", :as => :view_#{parent_plural_name}")
|
24
|
+
route("match \"#{child_plural_name}-for/:filename\" => \"view_#{parent_plural_name}#show\", :as => :view_#{parent_singular_name}")
|
25
|
+
route("match \"manage-#{child_plural_name}/:id\" => \"#{parent_plural_name}#manage\", :as => :manage_#{child_plural_name}")
|
26
|
+
route("match \"#{child_plural_name}/array\" => \"#{child_plural_name}#array\", :as => :#{child_plural_name}_sort")
|
27
|
+
route("match \"destroy-#{child_plural_name}\" => \"#{child_plural_name}#destroy\", :as => :#{child_plural_name}_bulk_delete")
|
28
|
+
|
29
|
+
route("resources :#{parent_plural_name}")
|
30
|
+
route("resources :#{child_plural_name}")
|
31
|
+
end
|
18
32
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
33
|
+
def app
|
34
|
+
template "app/controllers/albums_controller.rb", "app/controllers/#{parent_plural_name}_controller.rb"
|
35
|
+
template "app/controllers/photos_controller.rb", "app/controllers/#{child_plural_name}_controller.rb"
|
36
|
+
template "app/controllers/view_albums_controller.rb", "app/controllers/view_#{parent_plural_name}_controller.rb"
|
23
37
|
|
24
|
-
|
25
|
-
|
26
|
-
|
38
|
+
template "app/helpers/albums_helper.rb", "app/helpers/#{parent_plural_name}_helper.rb"
|
39
|
+
template "app/helpers/photos_helper.rb", "app/helpers/#{child_plural_name}_helper.rb"
|
40
|
+
template "app/helpers/view_albums_helper.rb", "app/helpers/view_#{parent_plural_name}_helper.rb"
|
27
41
|
|
28
|
-
|
29
|
-
|
42
|
+
template "app/models/album.rb", "app/models/#{parent_singular_name}.rb"
|
43
|
+
template "app/models/photo.rb", "app/models/#{child_singular_name}.rb"
|
30
44
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
45
|
+
template "app/views/albums/_form.html.erb", "app/views/#{parent_plural_name}/_form.html.erb"
|
46
|
+
template "app/views/albums/_search.html.erb", "app/views/#{parent_plural_name}/_search.html.erb"
|
47
|
+
template "app/views/albums/_upload_script.html.erb", "app/views/#{parent_plural_name}/_upload_script.html.erb"
|
48
|
+
template "app/views/albums/edit.html.erb", "app/views/#{parent_plural_name}/edit.html.erb"
|
49
|
+
template "app/views/albums/index.html.erb", "app/views/#{parent_plural_name}/index.html.erb"
|
50
|
+
template "app/views/albums/manage.html.erb", "app/views/#{parent_plural_name}/manage.html.erb"
|
51
|
+
template "app/views/albums/new.html.erb", "app/views/#{parent_plural_name}/new.html.erb"
|
52
|
+
template "app/views/albums/show.html.erb", "app/views/#{parent_plural_name}/show.html.erb"
|
53
|
+
template "app/views/albums/show.js.erb", "app/views/#{parent_plural_name}/show.js.erb"
|
37
54
|
|
38
|
-
|
39
|
-
|
55
|
+
template "app/views/photos/_form.html.erb", "app/views/#{child_plural_name}/_form.html.erb"
|
56
|
+
template "app/views/photos/_search.html.erb", "app/views/#{child_plural_name}/_search.html.erb"
|
57
|
+
template "app/views/photos/_photo.html.erb", "app/views/#{child_plural_name}/_#{child_singular_name}.html.erb"
|
58
|
+
template "app/views/photos/array.js.erb", "app/views/#{child_plural_name}/array.js.erb"
|
59
|
+
template "app/views/photos/edit.html.erb", "app/views/#{child_plural_name}/edit.html.erb"
|
60
|
+
template "app/views/photos/index.html.erb", "app/views/#{child_plural_name}/index.html.erb"
|
61
|
+
template "app/views/photos/new.html.erb", "app/views/#{child_plural_name}/new.html.erb"
|
62
|
+
template "app/views/photos/show.html.erb", "app/views/#{child_plural_name}/show.html.erb"
|
63
|
+
template "app/views/photos/show.js.erb", "app/views/#{child_plural_name}/show.js.erb"
|
40
64
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
65
|
+
template "app/views/view_albums/index.html.erb", "app/views/view_#{parent_plural_name}/index.html.erb"
|
66
|
+
template "app/views/view_albums/show.html.erb", "app/views/view_#{parent_plural_name}/show.html.erb"
|
67
|
+
end
|
68
|
+
|
69
|
+
def css
|
70
|
+
template "stylesheets/dust_album.css", "public/stylesheets/dust_#{parent_singular_name}.css"
|
71
|
+
template "stylesheets/uploadify.css", "public/stylesheets/#{parent_singular_name}_uploadify.css"
|
72
|
+
template "stylesheets/dust_album_app.css", "public/stylesheets/dust_#{parent_singular_name}_app.css"
|
73
|
+
end
|
46
74
|
|
47
|
-
|
48
|
-
|
75
|
+
def javascript
|
76
|
+
template "javascripts/dragsort.js", "public/javascripts/dragsort.js"
|
77
|
+
template "javascripts/dust_album.js", "public/javascripts/dust_#{parent_singular_name}.js"
|
49
78
|
|
50
|
-
|
51
|
-
|
79
|
+
src_dir = File.join(source_root, 'javascripts', 'uploadify')
|
80
|
+
dst_dir = File.join(RAILS_ROOT, 'public', 'javascripts')
|
52
81
|
|
82
|
+
FileUtils.cp_r src_dir, dst_dir, :verbose => true
|
83
|
+
end
|
84
|
+
|
85
|
+
def images
|
86
|
+
template "images/cancel.png", "public/images/cancel.png"
|
87
|
+
template "images/browse.png", "public/images/browse.png"
|
88
|
+
template "images/upload.png", "public/images/upload.png"
|
89
|
+
template "images/save_position.png", "public/images/save_position.png"
|
90
|
+
end
|
91
|
+
|
92
|
+
def initializers
|
93
|
+
template "initializers/flash_session_cookie_middleware.rb", "config/initializers/flash_session_cookie_middleware.rb"
|
94
|
+
template "initializers/session_store_middleware.rb", "config/initializers/session_store_middleware.rb"
|
95
|
+
end
|
96
|
+
|
53
97
|
def rake_migrations
|
54
98
|
rake("db:migrate")
|
55
99
|
end
|
100
|
+
|
101
|
+
#NAMING METHODS
|
102
|
+
def parent
|
103
|
+
parent_model_name.downcase.singularize
|
104
|
+
end
|
105
|
+
|
106
|
+
def child
|
107
|
+
child_model_name.downcase.singularize
|
108
|
+
end
|
109
|
+
|
110
|
+
def parent_singular_name
|
111
|
+
parent.underscore
|
112
|
+
end
|
113
|
+
|
114
|
+
def child_singular_name
|
115
|
+
child.underscore
|
116
|
+
end
|
117
|
+
|
118
|
+
def parent_plural_name
|
119
|
+
parent.underscore.pluralize
|
120
|
+
end
|
121
|
+
|
122
|
+
def child_plural_name
|
123
|
+
child.underscore.pluralize
|
124
|
+
end
|
125
|
+
|
126
|
+
def parent_class_name
|
127
|
+
parent.camelize
|
128
|
+
end
|
129
|
+
|
130
|
+
def child_class_name
|
131
|
+
child.camelize
|
132
|
+
end
|
133
|
+
|
134
|
+
def parent_plural_class_name
|
135
|
+
parent_plural_name.camelize
|
136
|
+
end
|
137
|
+
|
138
|
+
def child_plural_class_name
|
139
|
+
child_plural_name.camelize
|
140
|
+
end
|
141
|
+
|
142
|
+
# FIXME: Should be proxied to ActiveRecord::Generators::Base
|
143
|
+
# Implement the required interface for Rails::Generators::Migration.
|
144
|
+
def self.next_migration_number(dirname) #:nodoc:
|
145
|
+
if ActiveRecord::Base.timestamped_migrations
|
146
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
147
|
+
else
|
148
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
149
|
+
end
|
150
|
+
end
|
56
151
|
end
|
57
152
|
end
|
58
153
|
end
|
@@ -1,50 +1,56 @@
|
|
1
|
-
class
|
1
|
+
class <%=parent_plural_class_name%>Controller < ApplicationController
|
2
2
|
|
3
3
|
filter_resource_access
|
4
4
|
|
5
5
|
layout 'cms'
|
6
6
|
|
7
7
|
def index
|
8
|
-
|
8
|
+
@<%=parent_plural_name%> = <%=parent_class_name%>.page(params[:search], params[:page])
|
9
9
|
end
|
10
10
|
|
11
11
|
def show
|
12
|
-
|
13
|
-
@
|
12
|
+
@<%=parent_singular_name%> = <%=parent_class_name%>.find(params[:id], :include => :<%=child_plural_name%>)
|
13
|
+
@new_<%=child_singular_name%> = <%=child_class_name%>.new(:<%=parent_singular_name%>_id => @<%=parent_singular_name%>.id)
|
14
14
|
end
|
15
15
|
|
16
16
|
def new
|
17
|
-
|
17
|
+
@<%=parent_singular_name%> = <%=parent_class_name%>.new
|
18
18
|
end
|
19
19
|
|
20
20
|
def create
|
21
|
-
|
22
|
-
if
|
23
|
-
flash[:notice] = "Successfully created
|
24
|
-
redirect_to
|
21
|
+
@<%=parent_singular_name%> = <%=parent_class_name%>.new(params[:<%=parent_singular_name%>])
|
22
|
+
if @<%=parent_singular_name%>.save
|
23
|
+
flash[:notice] = "Successfully created <%=parent_singular_name%>."
|
24
|
+
redirect_to @<%=parent_singular_name%>
|
25
25
|
else
|
26
26
|
render :action => 'new'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
def edit
|
31
|
-
|
31
|
+
@<%=parent_singular_name%> = <%=parent_class_name%>.find(params[:id])
|
32
32
|
end
|
33
33
|
|
34
34
|
def update
|
35
|
-
|
36
|
-
if
|
37
|
-
flash[:notice] = "Successfully updated
|
38
|
-
redirect_to
|
35
|
+
@<%=parent_singular_name%> = <%=parent_class_name%>.find(params[:id])
|
36
|
+
if @<%=parent_singular_name%>.update_attributes(params[:<%=parent_singular_name%>])
|
37
|
+
flash[:notice] = "Successfully updated <%=parent_singular_name%>."
|
38
|
+
redirect_to view_<%=parent_singular_name%>_path(@<%=parent_singular_name%>.filename)
|
39
39
|
else
|
40
40
|
render :action => 'edit'
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
def destroy
|
45
|
-
|
46
|
-
|
47
|
-
flash[:notice] = "Successfully destroyed
|
48
|
-
redirect_to
|
45
|
+
@<%=parent_singular_name%> = <%=parent_class_name%>.find(params[:id])
|
46
|
+
@<%=parent_singular_name%>.destroy
|
47
|
+
flash[:notice] = "Successfully destroyed <%=parent_singular_name%>."
|
48
|
+
redirect_to <%=parent_plural_name%>_url
|
49
49
|
end
|
50
|
+
|
51
|
+
def manage
|
52
|
+
@<%=parent_singular_name%> = <%=parent_class_name%>.find(params[:id], :include => :<%=child_plural_name%>)
|
53
|
+
@<%=child_plural_name%> = @<%=parent_singular_name%>.<%=child_plural_name%>
|
54
|
+
render :layout => false
|
55
|
+
end
|
50
56
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class <%=child_plural_class_name%>Controller < ApplicationController
|
2
2
|
|
3
3
|
filter_access_to :index, :new, :create, :destroy
|
4
4
|
filter_access_to :edit, :update, :attribute_check => true
|
@@ -6,27 +6,28 @@ class PhotosController < ApplicationController
|
|
6
6
|
layout 'cms'
|
7
7
|
|
8
8
|
def index
|
9
|
-
|
10
|
-
|
9
|
+
@<%=child_plural_name%> = <%=child_class_name%>.page(params[:search], params[:page])
|
10
|
+
@<%=child_singular_name%>_<%=parent_plural_name%> = @<%=child_plural_name%>.group_by { |<%=child_singular_name%>| <%=child_singular_name%>.<%=parent_singular_name%>.title }
|
11
11
|
end
|
12
12
|
|
13
13
|
def show
|
14
|
-
|
15
|
-
@total_uploads =
|
14
|
+
@<%=child_singular_name%> = <%=child_class_name%>.find(params[:id], :include => :<%=parent_singular_name%>)
|
15
|
+
@total_uploads = <%=child_class_name%>.find(:all, :conditions => { :<%=parent_singular_name%>_id => @<%=child_singular_name%>.<%=parent_singular_name%>.id})
|
16
|
+
@<%=parent_singular_name%> = @<%=child_singular_name%>.<%=parent_singular_name%>
|
16
17
|
end
|
17
18
|
|
18
19
|
def new
|
19
|
-
|
20
|
+
@<%=child_singular_name%> = <%=child_class_name%>.new
|
20
21
|
end
|
21
22
|
|
22
23
|
def create
|
23
24
|
newparams = coerce(params)
|
24
|
-
|
25
|
-
if
|
26
|
-
flash[:notice] = "Successfully created
|
25
|
+
@<%=child_singular_name%> = <%=child_class_name%>.new(newparams[:<%=child_singular_name%>])
|
26
|
+
if @<%=child_singular_name%>.save
|
27
|
+
flash[:notice] = "Successfully created <%=child_singular_name%>."
|
27
28
|
respond_to do |format|
|
28
|
-
format.html { redirect_to
|
29
|
-
format.json { render :json => { :result => 'success',
|
29
|
+
format.html { redirect_to @<%=child_singular_name%>.<%=parent_singular_name%> }
|
30
|
+
format.json { render :json => { :result => 'success', :<%=child_singular_name%> => <%=child_singular_name%>_url(@<%=child_singular_name%>) } }
|
30
31
|
end
|
31
32
|
else
|
32
33
|
render :action => 'new'
|
@@ -34,55 +35,51 @@ class PhotosController < ApplicationController
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def edit
|
37
|
-
if params[:edit] == '
|
38
|
+
if params[:edit] == '<%=child_singular_name%>'
|
38
39
|
render :layout => false
|
39
|
-
|
40
|
+
@<%=child_singular_name%> = <%=child_class_name%>.find(params[:id])
|
40
41
|
else
|
41
|
-
|
42
|
+
@<%=child_singular_name%> = <%=child_class_name%>.find(params[:id])
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
46
|
def update
|
46
|
-
|
47
|
-
if
|
48
|
-
flash[:notice] = "Successfully updated
|
49
|
-
|
50
|
-
format.html { redirect_to album_url(@photo.album)}
|
51
|
-
format.js { render :json => { :result => 'success', :album => album_url(@photo.album) } }
|
52
|
-
end
|
47
|
+
@<%=child_singular_name%> = <%=child_class_name%>.find(params[:id])
|
48
|
+
if @<%=child_singular_name%>.update_attributes(params[:<%=child_singular_name%>])
|
49
|
+
flash[:notice] = "Successfully updated <%=child_singular_name%>."
|
50
|
+
redirect_to <%=parent_singular_name%>_url(@<%=child_singular_name%>.<%=parent_singular_name%>)
|
53
51
|
else
|
54
52
|
render :action => 'edit'
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
58
|
-
|
56
|
+
def destroy
|
59
57
|
if request.post?
|
60
|
-
if params[
|
61
|
-
params[
|
62
|
-
|
63
|
-
|
58
|
+
if params[:<%=child_singular_name%>_ids]
|
59
|
+
params[:<%=child_singular_name%>_ids].each do |<%=child_singular_name%>|
|
60
|
+
@<%=child_singular_name%> = <%=child_class_name%>.find <%=child_singular_name%>
|
61
|
+
@<%=child_singular_name%>.destroy
|
64
62
|
end
|
65
|
-
flash[:notice] = "
|
63
|
+
flash[:notice] = "<%=child_plural_class_name%> Successfully deleted!"
|
66
64
|
end
|
67
|
-
|
68
|
-
if Photo.all.blank?
|
69
|
-
format.html { redirect_to(albums_url) }
|
70
|
-
else
|
71
|
-
format.html { redirect_to(:back) }
|
72
|
-
end
|
73
|
-
end
|
65
|
+
redirect_to(<%=parent_singular_name%>_path(@<%=child_singular_name%>.<%=parent_singular_name%>))
|
74
66
|
end
|
75
67
|
end
|
76
68
|
|
69
|
+
def array
|
70
|
+
menu_sort(params[:ul])
|
71
|
+
flash[:notice] = "Successfully Sorted <%=child_plural_class_name%>."
|
72
|
+
end
|
73
|
+
|
77
74
|
private
|
78
75
|
def coerce(params)
|
79
|
-
if params[
|
76
|
+
if params[:<%=child_singular_name%>].nil?
|
80
77
|
h = Hash.new
|
81
|
-
h[
|
82
|
-
h[
|
83
|
-
h[
|
84
|
-
h[
|
85
|
-
h[
|
78
|
+
h[:<%=child_singular_name%>] = Hash.new
|
79
|
+
h[:<%=child_singular_name%>][:<%=parent_singular_name%>_id] = params[:<%=parent_singular_name%>_id]
|
80
|
+
h[:<%=child_singular_name%>][:title] = params[:title]
|
81
|
+
h[:<%=child_singular_name%>][:file] = params[:Filedata]
|
82
|
+
h[:<%=child_singular_name%>][:file].content_type = MIME::Types.type_for(h[:<%=child_singular_name%>][:file].original_filename).to_s
|
86
83
|
h
|
87
84
|
else
|
88
85
|
params
|
@@ -1,17 +1,16 @@
|
|
1
|
-
class
|
2
|
-
unloadable
|
1
|
+
class View<%=parent_plural_class_name%>Controller < ApplicationController
|
3
2
|
|
4
3
|
def index
|
5
|
-
|
4
|
+
@<%=parent_plural_name%> = <%=parent_class_name%>.view(params[:page])
|
6
5
|
end
|
7
6
|
|
8
7
|
def show
|
9
|
-
if
|
10
|
-
|
8
|
+
if <%=parent_class_name%>.find_by_filename(params[:filename]) == nil
|
9
|
+
@<%=parent_singular_name%> = <%=parent_class_name%>.find(:first)
|
11
10
|
render :file => "#{RAILS_ROOT}/public/404.html", :layout => false, :status => 404
|
12
11
|
else
|
13
|
-
|
14
|
-
|
12
|
+
@<%=parent_singular_name%> = <%=parent_class_name%>.find_by_filename(params[:filename])
|
13
|
+
@<%=child_plural_name%> = @<%=parent_singular_name%>.<%=child_plural_name%>.<%=parent_singular_name%>_page(params[:page])
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
@@ -1,2 +1,2 @@
|
|
1
|
-
module
|
1
|
+
module <%=parent_plural_class_name%>Helper
|
2
2
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
module
|
1
|
+
module <%=child_plural_class_name%>Helper
|
2
2
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
module
|
1
|
+
module View<%=parent_plural_class_name%>Helper
|
2
2
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
class
|
1
|
+
class <%=parent_class_name%> < ActiveRecord::Base
|
2
2
|
|
3
|
-
has_many
|
3
|
+
has_many :<%=child_plural_name%>, :dependent => :destroy
|
4
4
|
|
5
5
|
validates_presence_of :title
|
6
6
|
validates_presence_of :filename
|
@@ -10,6 +10,10 @@ class Album < ActiveRecord::Base
|
|
10
10
|
with_permissions_to(:manage).search(search).order("title").paginate(:per_page => 10, :page => page)
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.view(page)
|
14
|
+
order("position").paginate(:per_page => 10, :page => page)
|
15
|
+
end
|
16
|
+
|
13
17
|
def self.search(search)
|
14
18
|
if search
|
15
19
|
where("title LIKE ?", "%#{search}%")
|
@@ -30,7 +34,7 @@ class Album < ActiveRecord::Base
|
|
30
34
|
else
|
31
35
|
@menu_item.update_attributes(
|
32
36
|
:title => self.title,
|
33
|
-
:url => "
|
37
|
+
:url => "/<%=child_plural_name%>-for/#{self.filename}",
|
34
38
|
:active => self.active
|
35
39
|
)
|
36
40
|
end
|
@@ -39,7 +43,7 @@ class Album < ActiveRecord::Base
|
|
39
43
|
def create_menu_item
|
40
44
|
@menu_item = self.build_menu_item(
|
41
45
|
:title => self.title,
|
42
|
-
:url => "
|
46
|
+
:url => "/<%=child_plural_name%>-for/#{self.filename}",
|
43
47
|
:active => self.active
|
44
48
|
)
|
45
49
|
@menu_item.save
|