public
Description: A Rails Plugin that simply adds typical REST actions to a controller.
Clone URL: git://github.com/coderifous/basic_rest_actions.git
Added find_for_resources and find_for_resource.

Let's controllers easily customize the finder code without having to 
override
an entire action.
coderifous (author)
Wed Jul 02 08:24:30 -0700 2008
commit  fed0ca4b361b441f27208c44682edae5d814d66a
tree    adf7182f516c37cc9425adffa9344f73ad23c50a
parent  0c916ee5f348838d3fb45533e6404dd88dd9a684
...
42
43
44
 
 
 
 
 
 
 
 
 
 
45
46
47
48
 
49
50
51
 
52
53
 
54
55
56
...
60
61
62
63
 
64
65
66
...
70
71
72
73
 
74
75
76
77
78
79
 
80
81
82
...
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 
58
59
60
 
61
62
 
63
64
65
66
...
70
71
72
 
73
74
75
76
...
80
81
82
 
83
84
85
86
87
88
 
89
90
91
92
0
@@ -42,15 +42,25 @@ module BasicRestActions
0
 
0
   module RestMethods
0
     
0
+ # override this method to change the finder used in index
0
+ def find_for_resources
0
+ model_class.find(:all)
0
+ end
0
+
0
+ # override this method to change the finder used in every other action
0
+ def find_for_resource
0
+ model_class.find(params[:id])
0
+ end
0
+
0
     # TODO: add support for finder :conditions anywhere you see a find
0
     # TODO: add support for pre-respond_to hooks (maybe)
0
     def index
0
- @models = model_class.find(:all)
0
+ @models = find_for_resources
0
       standard_respond_to
0
     end
0
-
0
+
0
     def show
0
- @model = model_class.find(params[:id])
0
+ @model = find_for_resource
0
       standard_respond_to
0
     end
0
   
0
@@ -60,7 +70,7 @@ module BasicRestActions
0
     end
0
   
0
     def edit
0
- @model = model_class.find(params[:id])
0
+ @model = find_for_resource
0
       set_friendly_instance_variable
0
     end
0
   
0
@@ -70,13 +80,13 @@ module BasicRestActions
0
     end
0
   
0
     def update
0
- @model = model_class.find(params[:id])
0
+ @model = find_for_resource
0
       @model.attributes = params[friendly_model_var_name]
0
       save_and_respond_to
0
     end
0
 
0
     def destroy
0
- @model = model_class.find(params[:id])
0
+ @model = find_for_resource
0
       @model.destroy
0
       set_friendly_instance_variable
0
       respond_to do |format|

Comments

    No one has commented yet.