nileshtrivedi-lp_resource_builder 0.5.1 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -12
- data/Rakefile +7 -20
- data/generators/scaffold_resource/templates/view__form.erb +2 -1
- data/generators/scaffold_resource/templates/view_partial_edit.html.erb +0 -2
- data/generators/scaffold_resource/templates/view_partial_new.html.erb +0 -2
- data/lib/resource_controller/helpers/current_objects.rb +63 -59
- data/lib/resource_controller/helpers/internal.rb +69 -65
- data/lib/resource_controller/helpers/nested.rb +54 -50
- data/lib/resource_controller/helpers/singleton_customizations.rb +50 -46
- data/lib/resource_controller/helpers/urls.rb +73 -69
- data/test/app/models/photo.rb +1 -0
- data/test/config/environment.rb +1 -18
- data/test/config/routes.rb +3 -0
- data/test/db/schema.rb +9 -3
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -6,23 +6,15 @@ resource_controller makes RESTful controllers easier, more maintainable, and sup
|
|
6
6
|
|
7
7
|
Add it as a gem dependency
|
8
8
|
|
9
|
-
config.gem 'resource_controller'
|
10
|
-
|
11
|
-
...or for the development version
|
12
|
-
|
13
|
-
config.gem 'giraffesoft-resource_controller', :lib => 'resource_controller', :source => 'http://gems.github.com'
|
9
|
+
config.gem 'nileshtrivedi-lp_resource_builder', :lib => 'resource_controller', :source => 'http://gems.github.com'
|
14
10
|
|
15
11
|
Or install it as a gem manually
|
16
12
|
|
17
|
-
sudo gem install
|
18
|
-
|
19
|
-
...or for the development version
|
20
|
-
|
21
|
-
sudo gem install giraffesoft-resource_controller
|
13
|
+
sudo gem install nileshtrivedi-lp_resource_builder
|
22
14
|
|
23
15
|
Or grab the source
|
24
16
|
|
25
|
-
git clone git://github.com/
|
17
|
+
git clone git://github.com/nileshtrivedi/resource_controller.git
|
26
18
|
|
27
19
|
= Usage
|
28
20
|
|
@@ -318,7 +310,7 @@ Or with namespaced, nested controllers...
|
|
318
310
|
You get the idea. Everything is automagical! All parameters are inferred.
|
319
311
|
|
320
312
|
== Credits
|
321
|
-
|
313
|
+
resource_builder is a fork of resource_controller, maintained by {Nilesh Trivedi}[http://nileshtrivedi.in]
|
322
314
|
resource_controller was created, and is maintained by {James Golick}[http://jamesgolick.com].
|
323
315
|
|
324
316
|
== License
|
data/Rakefile
CHANGED
@@ -1,26 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
require File.dirname(__FILE__)+'/lib/resource_controller/version'
|
5
|
-
Dir['tasks/**.rake'].each { |tasks| load tasks }
|
6
|
-
|
7
|
-
desc 'Default: run unit tests.'
|
8
|
-
task :default => :test
|
9
|
-
|
10
|
-
desc 'Test the ResourceController plugin.'
|
11
|
-
Rake::TestTask.new(:test) do |t|
|
12
|
-
t.libs << 'lib'
|
13
|
-
t.pattern = 'test/test/**/*_test.rb'
|
14
|
-
t.verbose = true
|
15
|
-
end
|
1
|
+
Dir.chdir('test')
|
2
|
+
load 'Rakefile'
|
16
3
|
|
17
4
|
desc 'Generate documentation for the ResourceController plugin.'
|
18
5
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
19
|
-
rdoc.rdoc_dir = 'rdoc'
|
6
|
+
rdoc.rdoc_dir = '../rdoc'
|
20
7
|
rdoc.title = 'ResourceController'
|
21
8
|
rdoc.options << '--line-numbers' << '--inline-source'
|
22
|
-
rdoc.rdoc_files.include('README.rdoc')
|
23
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
9
|
+
rdoc.rdoc_files.include('../README.rdoc')
|
10
|
+
rdoc.rdoc_files.include('../lib/**/*.rb')
|
24
11
|
end
|
25
12
|
|
26
13
|
task :upload_docs => :rdoc do
|
@@ -28,8 +15,8 @@ task :upload_docs => :rdoc do
|
|
28
15
|
`ssh jamesgolick.com 'rm -Rf /home/apps/jamesgolick.com/public/resource_controller/rdoc'`
|
29
16
|
|
30
17
|
puts "Uploading current rdoc"
|
31
|
-
`scp -r rdoc jamesgolick.com:/home/apps/jamesgolick.com/public/resource_controller`
|
18
|
+
`scp -r ../rdoc jamesgolick.com:/home/apps/jamesgolick.com/public/resource_controller`
|
32
19
|
|
33
20
|
puts "Deleting rdoc"
|
34
|
-
`rm -Rf rdoc`
|
21
|
+
`rm -Rf ../rdoc`
|
35
22
|
end
|
@@ -2,5 +2,6 @@
|
|
2
2
|
<p>
|
3
3
|
<label for="<%= singular_name %>_<%= attribute.name %>"><%= attribute.column.human_name %>:</label>
|
4
4
|
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
5
|
+
<%%= error_message_on "<%= singular_name %>", "<%= attribute.name %>" %>
|
5
6
|
</p>
|
6
|
-
<% end -%>
|
7
|
+
<% end -%>
|
@@ -1,8 +1,6 @@
|
|
1
1
|
<%% if @<%= singular_name %>.editable_by?(current_user) %>
|
2
2
|
<h1>Editing <%= singular_name.titleize %></h1>
|
3
|
-
|
4
3
|
<%%= error_messages_for :<%= singular_name %> %>
|
5
|
-
|
6
4
|
<%% form_for(:<%= singular_name %>, :url => object_url, :html => { :method => :put }) do |f| %>
|
7
5
|
<%%= render(:partial => "form", :locals => {:f => f}) %>
|
8
6
|
<p>
|
@@ -1,69 +1,73 @@
|
|
1
|
-
module ResourceController
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module ResourceController
|
2
|
+
module Helpers
|
3
|
+
module CurrentObjects
|
4
|
+
protected
|
5
|
+
# Used internally to return the model for your resource.
|
6
|
+
#
|
7
|
+
def model
|
8
|
+
model_name.to_s.camelize.constantize
|
9
|
+
end
|
8
10
|
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
# Used to fetch the collection for the index method
|
13
|
+
#
|
14
|
+
# In order to customize the way the collection is fetched, to add something like pagination, for example, override this method.
|
15
|
+
#
|
16
|
+
def collection
|
17
|
+
end_of_association_chain.find(:all)
|
18
|
+
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
# Returns the current param.
|
21
|
+
#
|
22
|
+
# Defaults to params[:id].
|
23
|
+
#
|
24
|
+
# Override this method if you'd like to use an alternate param name.
|
25
|
+
#
|
26
|
+
def param
|
27
|
+
params[:id]
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
30
|
+
# Used to fetch the current member object in all of the singular methods that operate on an existing member.
|
31
|
+
#
|
32
|
+
# Override this method if you'd like to fetch your objects in some alternate way, like using a permalink.
|
33
|
+
#
|
34
|
+
# class PostsController < ResourceController::Base
|
35
|
+
# private
|
36
|
+
# def object
|
37
|
+
# @object ||= end_of_association_chain.find_by_permalink(param)
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
def object
|
42
|
+
@object ||= end_of_association_chain.find(param) unless param.nil?
|
43
|
+
@object
|
44
|
+
end
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
# Used internally to load the member object in to an instance variable @#{model_name} (i.e. @post)
|
47
|
+
#
|
48
|
+
def load_object
|
49
|
+
instance_variable_set "@#{parent_type}", parent_object if parent?
|
50
|
+
instance_variable_set "@#{object_name}", object
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
# Used internally to load the collection in to an instance variable @#{model_name.pluralize} (i.e. @posts)
|
54
|
+
#
|
55
|
+
def load_collection
|
56
|
+
instance_variable_set "@#{parent_type}", parent_object if parent?
|
57
|
+
instance_variable_set "@#{object_name.to_s.pluralize}", collection
|
58
|
+
end
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
# Returns the form params. Defaults to params[model_name] (i.e. params["post"])
|
61
|
+
#
|
62
|
+
def object_params
|
63
|
+
params["#{object_name}"]
|
64
|
+
end
|
63
65
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
# Builds the object, but doesn't save it, during the new, and create action.
|
67
|
+
#
|
68
|
+
def build_object
|
69
|
+
@object ||= end_of_association_chain.send parent? ? :build : :new, object_params
|
70
|
+
end
|
68
71
|
end
|
72
|
+
end
|
69
73
|
end
|
@@ -2,75 +2,79 @@
|
|
2
2
|
#
|
3
3
|
# All of these methods are used internally to execute the options, set by the user in ActionOptions and FailableActionOptions
|
4
4
|
#
|
5
|
-
module ResourceController
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
module ResourceController
|
6
|
+
module Helpers
|
7
|
+
module Internal
|
8
|
+
protected
|
9
|
+
# Used to actually pass the responses along to the controller's respond_to method.
|
10
|
+
#
|
11
|
+
def response_for(action)
|
12
|
+
respond_to do |wants|
|
13
|
+
options_for(action).response.each do |method, block|
|
14
|
+
if block.nil?
|
15
|
+
wants.send(method)
|
16
|
+
else
|
17
|
+
wants.send(method) { instance_eval(&block) }
|
18
|
+
end
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
18
|
-
|
19
|
-
|
22
|
+
|
23
|
+
# Calls the after callbacks for the action, if one is present.
|
24
|
+
#
|
25
|
+
def after(action)
|
26
|
+
invoke_callbacks *options_for(action).after
|
27
|
+
end
|
28
|
+
|
29
|
+
# Calls the before block for the action, if one is present.
|
30
|
+
#
|
31
|
+
def before(action)
|
32
|
+
invoke_callbacks *self.class.send(action).before
|
33
|
+
end
|
20
34
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
35
|
+
# Sets the flash and flash_now for the action, if it is present.
|
36
|
+
#
|
37
|
+
def set_flash(action)
|
38
|
+
set_normal_flash(action)
|
39
|
+
set_flash_now(action)
|
40
|
+
end
|
26
41
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
# Manages splitting things like :create_fails.
|
59
|
-
#
|
60
|
-
def options_for(action)
|
61
|
-
action = action == :new_action ? [action] : "#{action}".split('_').map(&:to_sym)
|
62
|
-
options = self.class.send(action.first)
|
63
|
-
options = options.send(action.last == :fails ? :fails : :success) if ResourceController::FAILABLE_ACTIONS.include? action.first
|
42
|
+
# Sets the regular flash (i.e. flash[:notice] = '...')
|
43
|
+
#
|
44
|
+
def set_normal_flash(action)
|
45
|
+
if f = options_for(action).flash
|
46
|
+
flash[:notice] = f.is_a?(Proc) ? instance_eval(&f) : options_for(action).flash
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Sets the flash.now (i.e. flash.now[:notice] = '...')
|
51
|
+
#
|
52
|
+
def set_flash_now(action)
|
53
|
+
if f = options_for(action).flash_now
|
54
|
+
flash.now[:notice] = f.is_a?(Proc) ? instance_eval(&f) : options_for(action).flash_now
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns the options for an action, which is a symbol.
|
59
|
+
#
|
60
|
+
# Manages splitting things like :create_fails.
|
61
|
+
#
|
62
|
+
def options_for(action)
|
63
|
+
action = action == :new_action ? [action] : "#{action}".split('_').map(&:to_sym)
|
64
|
+
options = self.class.send(action.first)
|
65
|
+
options = options.send(action.last == :fails ? :fails : :success) if ResourceController::FAILABLE_ACTIONS.include? action.first
|
66
|
+
|
67
|
+
options
|
68
|
+
end
|
69
|
+
|
70
|
+
def invoke_callbacks(*callbacks)
|
71
|
+
unless callbacks.empty?
|
72
|
+
callbacks.select { |callback| callback.is_a? Symbol }.each { |symbol| send(symbol) }
|
64
73
|
|
65
|
-
|
74
|
+
block = callbacks.detect { |callback| callback.is_a? Proc }
|
75
|
+
instance_eval &block unless block.nil?
|
76
|
+
end
|
77
|
+
end
|
66
78
|
end
|
67
|
-
|
68
|
-
def invoke_callbacks(*callbacks)
|
69
|
-
unless callbacks.empty?
|
70
|
-
callbacks.select { |callback| callback.is_a? Symbol }.each { |symbol| send(symbol) }
|
71
|
-
|
72
|
-
block = callbacks.detect { |callback| callback.is_a? Proc }
|
73
|
-
instance_eval &block unless block.nil?
|
74
|
-
end
|
75
|
-
end
|
79
|
+
end
|
76
80
|
end
|
@@ -1,63 +1,67 @@
|
|
1
1
|
# Nested and Polymorphic Resource Helpers
|
2
2
|
#
|
3
|
-
module ResourceController
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
module ResourceController
|
4
|
+
module Helpers
|
5
|
+
module Nested
|
6
|
+
protected
|
7
|
+
# Returns the relevant association proxy of the parent. (i.e. /posts/1/comments # => @post.comments)
|
8
|
+
#
|
9
|
+
def parent_association
|
10
|
+
@parent_association ||= parent_object.send(model_name.to_s.pluralize.to_sym)
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
# Returns the type of the current parent
|
14
|
+
#
|
15
|
+
def parent_type
|
16
|
+
@parent_type ||= parent_type_from_params || parent_type_from_request
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
# Returns the type of the current parent extracted from params
|
20
|
+
#
|
21
|
+
def parent_type_from_params
|
22
|
+
[*belongs_to].find { |parent| !params["#{parent}_id".to_sym].nil? }
|
23
|
+
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
# Returns the type of the current parent extracted form a request path
|
26
|
+
#
|
27
|
+
def parent_type_from_request
|
28
|
+
[*belongs_to].find { |parent| request.path.split('/').include? parent.to_s }
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
# Returns true/false based on whether or not a parent is present.
|
32
|
+
#
|
33
|
+
def parent?
|
34
|
+
!parent_type.nil?
|
35
|
+
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
# Returns true/false based on whether or not a parent is a singleton.
|
38
|
+
#
|
39
|
+
def parent_singleton?
|
40
|
+
!parent_type_from_request.nil? && parent_type_from_params.nil?
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
# Returns the current parent param, if there is a parent. (i.e. params[:post_id])
|
44
|
+
def parent_param
|
45
|
+
params["#{parent_type}_id".to_sym]
|
46
|
+
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
# Like the model method, but for a parent relationship.
|
49
|
+
#
|
50
|
+
def parent_model
|
51
|
+
parent_type.to_s.camelize.constantize
|
52
|
+
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
# Returns the current parent object if a parent object is present.
|
55
|
+
#
|
56
|
+
def parent_object
|
57
|
+
parent? && !parent_singleton? ? parent_model.find(parent_param) : nil
|
58
|
+
end
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
# If there is a parent, returns the relevant association proxy. Otherwise returns model.
|
61
|
+
#
|
62
|
+
def end_of_association_chain
|
63
|
+
parent? ? parent_association : model
|
64
|
+
end
|
62
65
|
end
|
66
|
+
end
|
63
67
|
end
|
@@ -2,59 +2,63 @@
|
|
2
2
|
#
|
3
3
|
# Used internally to transform a plural RESTful controller into a singleton
|
4
4
|
#
|
5
|
-
module ResourceController
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
module ResourceController
|
6
|
+
module Helpers
|
7
|
+
module SingletonCustomizations
|
8
|
+
def self.included(subclass)
|
9
|
+
subclass.class_eval do
|
10
|
+
methods_to_undefine = [:param, :index, :collection, :load_collection, :collection_url,
|
11
|
+
:collection_path, :hash_for_collection_url, :hash_for_collection_path]
|
12
|
+
methods_to_undefine.each { |method| undef_method(method) if method_defined? method }
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
class << self
|
15
|
+
def singleton?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
18
|
-
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
protected
|
23
|
+
# Used to fetch the current object in a singleton controller.
|
24
|
+
#
|
25
|
+
# By defult this method is able to fetch the current object for resources nested with the :has_one association only. (i.e. /users/1/image # => @user.image)
|
26
|
+
# In other cases you should override this method and provide your custom code to fetch a singleton resource object, like using a session hash.
|
27
|
+
#
|
28
|
+
# class AccountsController < ResourceController::Singleton
|
29
|
+
# private
|
30
|
+
# def object
|
31
|
+
# @object ||= Account.find(session[:account_id])
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
def object
|
36
|
+
@object ||= parent? ? end_of_association_chain : nil
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
# Returns the :has_one association proxy of the parent. (i.e. /users/1/image # => @user.image)
|
40
|
+
#
|
41
|
+
def parent_association
|
42
|
+
@parent_association ||= parent_object.send(model_name.to_sym)
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
# Used internally to provide the options to smart_url in a singleton controller.
|
46
|
+
#
|
47
|
+
def object_url_options(action_prefix = nil, alternate_object = nil)
|
48
|
+
[action_prefix] + namespaces + [parent_url_options, route_name.to_sym]
|
49
|
+
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
# Builds the object, but doesn't save it, during the new, and create action.
|
52
|
+
#
|
53
|
+
def build_object
|
54
|
+
@object ||= singleton_build_object_base.send parent? ? "build_#{model_name}".to_sym : :new, object_params
|
55
|
+
end
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
# Singleton controllers don't build off of association proxy, so we can't use end_of_association_chain here
|
58
|
+
#
|
59
|
+
def singleton_build_object_base
|
60
|
+
parent? ? parent_object : model
|
61
|
+
end
|
59
62
|
end
|
63
|
+
end
|
60
64
|
end
|
@@ -37,92 +37,96 @@
|
|
37
37
|
#
|
38
38
|
# You get the idea. Everything is automagical! All parameters are inferred.
|
39
39
|
#
|
40
|
-
module ResourceController
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
module ResourceController
|
41
|
+
module Helpers
|
42
|
+
module Urls
|
43
|
+
protected
|
44
|
+
['', 'edit_'].each do |type|
|
45
|
+
symbol = type.blank? ? nil : type.gsub(/_/, '').to_sym
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
define_method("#{type}object_url") do |*alternate_object|
|
48
|
+
smart_url *object_url_options(symbol, alternate_object.first)
|
49
|
+
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
define_method("#{type}object_path") do |*alternate_object|
|
52
|
+
smart_path *object_url_options(symbol, alternate_object.first)
|
53
|
+
end
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
define_method("hash_for_#{type}object_url") do |*alternate_object|
|
56
|
+
hash_for_smart_url *object_url_options(symbol, alternate_object.first)
|
57
|
+
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
define_method("hash_for_#{type}object_path") do |*alternate_object|
|
60
|
+
hash_for_smart_path *object_url_options(symbol, alternate_object.first)
|
61
|
+
end
|
62
|
+
end
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
|
64
|
+
def new_object_url
|
65
|
+
smart_url *new_object_url_options
|
66
|
+
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
68
|
+
def new_object_path
|
69
|
+
smart_path *new_object_url_options
|
70
|
+
end
|
69
71
|
|
70
|
-
|
71
|
-
|
72
|
-
|
72
|
+
def hash_for_new_object_url
|
73
|
+
hash_for_smart_url *new_object_url_options
|
74
|
+
end
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
-
|
76
|
+
def hash_for_new_object_path
|
77
|
+
hash_for_smart_path *new_object_url_options
|
78
|
+
end
|
77
79
|
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
def collection_url
|
81
|
+
smart_url *collection_url_options
|
82
|
+
end
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
-
|
84
|
+
def collection_path
|
85
|
+
smart_path *collection_url_options
|
86
|
+
end
|
85
87
|
|
86
|
-
|
87
|
-
|
88
|
-
|
88
|
+
def hash_for_collection_url
|
89
|
+
hash_for_smart_url *collection_url_options
|
90
|
+
end
|
89
91
|
|
90
|
-
|
91
|
-
|
92
|
-
|
92
|
+
def hash_for_collection_path
|
93
|
+
hash_for_smart_path *collection_url_options
|
94
|
+
end
|
93
95
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
# Used internally to provide the options to smart_url from Urligence.
|
97
|
+
#
|
98
|
+
def collection_url_options
|
99
|
+
namespaces + [parent_url_options, route_name.to_s.pluralize.to_sym]
|
100
|
+
end
|
99
101
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
# Used internally to provide the options to smart_url from Urligence.
|
103
|
+
#
|
104
|
+
def object_url_options(action_prefix = nil, alternate_object = nil)
|
105
|
+
[action_prefix] + namespaces + [parent_url_options, [route_name.to_sym, alternate_object || object]]
|
106
|
+
end
|
105
107
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
108
|
+
# Used internally to provide the options to smart_url from Urligence.
|
109
|
+
#
|
110
|
+
def new_object_url_options
|
111
|
+
[:new] + namespaces + [parent_url_options, route_name.to_sym]
|
112
|
+
end
|
111
113
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
114
|
+
def parent_url_options
|
115
|
+
if parent?
|
116
|
+
parent_singleton? ? parent_type.to_sym : [parent_type.to_sym, parent_object]
|
117
|
+
else
|
118
|
+
nil
|
119
|
+
end
|
120
|
+
end
|
119
121
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
122
|
+
# Returns all of the current namespaces of the current controller, symbolized, in array form.
|
123
|
+
#
|
124
|
+
def namespaces
|
125
|
+
names = self.class.name.split("::")
|
126
|
+
names.pop
|
125
127
|
|
126
|
-
|
128
|
+
names.map(&:underscore).map(&:to_sym)
|
129
|
+
end
|
127
130
|
end
|
131
|
+
end
|
128
132
|
end
|
data/test/app/models/photo.rb
CHANGED
data/test/config/environment.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# ENV['RAILS_ENV'] ||= 'production'
|
6
6
|
|
7
7
|
# Specifies gem version of Rails to use when vendor/rails is not present
|
8
|
-
RAILS_GEM_VERSION = '2.
|
8
|
+
RAILS_GEM_VERSION = '2.1.1' unless defined? RAILS_GEM_VERSION
|
9
9
|
|
10
10
|
# Bootstrap the Rails environment, frameworks, and default configuration
|
11
11
|
require File.join(File.dirname(__FILE__), 'boot')
|
@@ -45,20 +45,3 @@ Rails::Initializer.run do |config|
|
|
45
45
|
|
46
46
|
config.action_controller.session = { :session_key => "_myapp_session", :secret => "6c1372e61789239a727cdbc8252eb6da" }
|
47
47
|
end
|
48
|
-
|
49
|
-
require "#{RAILS_ROOT}/../init"
|
50
|
-
|
51
|
-
# Add new inflection rules using the following format
|
52
|
-
# (all these examples are active by default):
|
53
|
-
# Inflector.inflections do |inflect|
|
54
|
-
# inflect.plural /^(ox)$/i, '\1en'
|
55
|
-
# inflect.singular /^(ox)en/i, '\1'
|
56
|
-
# inflect.irregular 'person', 'people'
|
57
|
-
# inflect.uncountable %w( fish sheep )
|
58
|
-
# end
|
59
|
-
|
60
|
-
# Add new mime types for use in respond_to blocks:
|
61
|
-
# Mime::Type.register "text/richtext", :rtf
|
62
|
-
# Mime::Type.register "application/x-mobile", :mobile
|
63
|
-
|
64
|
-
# Include your application configuration below
|
data/test/config/routes.rb
CHANGED
data/test/db/schema.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# This file is auto-generated from the current state of the database. Instead of editing this file,
|
2
|
-
# please use the migrations feature of
|
2
|
+
# please use the migrations feature of Active Record to incrementally modify your database, and
|
3
3
|
# then regenerate this schema definition.
|
4
4
|
#
|
5
5
|
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
|
@@ -9,7 +9,7 @@
|
|
9
9
|
#
|
10
10
|
# It's strongly recommended to check this file into your version control system.
|
11
11
|
|
12
|
-
ActiveRecord::Schema.define(:version =>
|
12
|
+
ActiveRecord::Schema.define(:version => 14) do
|
13
13
|
|
14
14
|
create_table "accounts", :force => true do |t|
|
15
15
|
t.string "name"
|
@@ -33,9 +33,15 @@ ActiveRecord::Schema.define(:version => 12) do
|
|
33
33
|
t.string "title"
|
34
34
|
end
|
35
35
|
|
36
|
+
create_table "personnel", :force => true do |t|
|
37
|
+
t.datetime "created_at"
|
38
|
+
t.datetime "updated_at"
|
39
|
+
end
|
40
|
+
|
36
41
|
create_table "photos", :force => true do |t|
|
37
42
|
t.string "title"
|
38
43
|
t.integer "account_id"
|
44
|
+
t.integer "personnel_id"
|
39
45
|
end
|
40
46
|
|
41
47
|
create_table "photos_tags", :force => true do |t|
|
@@ -45,7 +51,7 @@ ActiveRecord::Schema.define(:version => 12) do
|
|
45
51
|
|
46
52
|
create_table "posts", :force => true do |t|
|
47
53
|
t.string "title", :default => ""
|
48
|
-
t.text "body"
|
54
|
+
t.text "body", :default => ""
|
49
55
|
end
|
50
56
|
|
51
57
|
create_table "products", :force => true do |t|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nileshtrivedi-lp_resource_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Golick
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2008-
|
13
|
+
date: 2008-10-16 21:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|