Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 452 lines (324 sloc) 15.343 kb
b614fb9 @josevalim Minor tweaks to README.
authored
1 == Inherited Resources
f0b92a4 @josevalim First commit! :)
authored
2
3 Inherited Resources speeds up development by making your controllers inherit
4 all restful actions so you just have to focus on what is important. It makes
5 your controllers more powerful and cleaner at the same time.
6
9263dee @josevalim Added more information on README.
authored
7 Plus, making your controllers follow a pattern, it helps you to write better
945c238 @josevalim Updated README with a link to Fabio Akita's screencast.
authored
8 code by following fat models and skinny controllers convention. There is
9 a screencast made by Fabio Akita about its features:
10
11 http://akitaonrails.com/2009/09/01/screencast-real-thin-restful-controllers-with-inherited-resources
9263dee @josevalim Added more information on README.
authored
12
de94d27 @josevalim Bump to 1.0 (gem will be published soon).
authored
13 Inherited Resources is tested and compatible with Rails 2.3.x.
0e34348 @josevalim Changing version for 0.1.1, which is compatible with Rails 2.3.0.
authored
14
5bba068 @josevalim Wrap everything before new release.
authored
15 == Installation
f0b92a4 @josevalim First commit! :)
authored
16
9207c29 @josevalim Remove has_scope from core.
authored
17 Inherited Resources is available as gem on Gemcutter, so just run the following:
f0b92a4 @josevalim First commit! :)
authored
18
6284ba8 @josevalim Talking about gemcutter on README.
authored
19 sudo gem install inherited_resources
f0b92a4 @josevalim First commit! :)
authored
20
21 If you want it as plugin, just do:
22
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
23 script/plugin install git://github.com/josevalim/inherited_resources.git
f0b92a4 @josevalim First commit! :)
authored
24
de94d27 @josevalim Bump to 1.0 (gem will be published soon).
authored
25 == Upgrading to Inherited Resources 1.0
9207c29 @josevalim Remove has_scope from core.
authored
26
de94d27 @josevalim Bump to 1.0 (gem will be published soon).
authored
27 Inherited Resources finally reached 1.0 version. A couple things changed,
28 so be sure to read the following sections:
9207c29 @josevalim Remove has_scope from core.
authored
29
30 === HasScope
31
de94d27 @josevalim Bump to 1.0 (gem will be published soon).
authored
32 Since Inherited Resources 1.0, has_scope is not part of its core anymore.
9207c29 @josevalim Remove has_scope from core.
authored
33 However, if you are using has_scope in your application, Inherited Resources
b614fb9 @josevalim Minor tweaks to README.
authored
34 will handle all the required hooks automatically.
9207c29 @josevalim Remove has_scope from core.
authored
35
36 has_scope gem is available at:
37
38 http://github.com/plataformatec/has_scope
39
40 And can be installed as:
41
42 sudo gem install has_scope
43
44 === Responders
45
de94d27 @josevalim Bump to 1.0 (gem will be published soon).
authored
46 Since Inherited Resources 1.0, responders are not part of its core anymore,
b614fb9 @josevalim Minor tweaks to README.
authored
47 but is set as Inherited Resources dependency and it's used by default by
48 InheritedResources controllers. Be sure to check the documentation to see
9207c29 @josevalim Remove has_scope from core.
authored
49 how it will change your application:
50
51 http://github.com/plataformatec/responders
52
53 And it can be installed as:
54
55 sudo gem install responders
56
b614fb9 @josevalim Minor tweaks to README.
authored
57 Using responders will set the flash message to :notice and :alert. You can change
9207c29 @josevalim Remove has_scope from core.
authored
58 that through the following configuration value:
59
60 InheritedResources.flash_keys = [ :success, :failure ]
61
a8751f4 @josevalim Change README to talk about rspec bug and polymorphic associations.
authored
62 == Rspec known bug
63
64 When used with integrate_views equals to false, rspec overwrites default_render,
65 render and some other controller methods which makes Inherited Resources not work
66 properly. In such cases, you have to set integrate_views to true.
67
5bba068 @josevalim Wrap everything before new release.
authored
68 == Basic Usage
f0b92a4 @josevalim First commit! :)
authored
69
70 To use Inherited Resources you just have to inherit (duh) it:
71
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
72 class ProjectsController < InheritedResources::Base
73 end
f0b92a4 @josevalim First commit! :)
authored
74
75 And all actions are defined and working, check it! Your projects collection
76 (in the index action) is still available in the instance variable @projects
de94d27 @josevalim Bump to 1.0 (gem will be published soon).
authored
77 and your project resource (all other actions) is available as @project.
f0b92a4 @josevalim First commit! :)
authored
78
79 The next step is to define which mime types this controller provides:
80
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
81 class ProjectsController < InheritedResources::Base
82 respond_to :html, :xml, :json
83 end
f0b92a4 @josevalim First commit! :)
authored
84
85 You can also specify them based per action:
86
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
87 class ProjectsController < InheritedResources::Base
88 respond_to :html, :xml, :json
89 respond_to :js, :only => :create
90 respond_to :iphone, :except => [ :edit, :update ]
91 end
f0b92a4 @josevalim First commit! :)
authored
92
f6fb96a @josevalim Updated README and moving to 0.7.0
authored
93 For each request, it first checkes if the "controller/action.format" file is
94 available (for example "projects/create.xml") and if it's not, it checks if
95 the resource respond to :to_format (in this case, :to_xml). Otherwise returns 404.
f0b92a4 @josevalim First commit! :)
authored
96
97 Another option is to specify which actions the controller will inherit from
98 the InheritedResources::Base:
99
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
100 class ProjectsController < InheritedResources::Base
101 actions :index, :show, :new, :create
102 end
f0b92a4 @josevalim First commit! :)
authored
103
104 Or:
105
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
106 class ProjectsController < InheritedResources::Base
107 actions :all, :except => [ :edit, :update, :destroy ]
108 end
f0b92a4 @josevalim First commit! :)
authored
109
960671b @josevalim Added parents helpers when using polymorphic controllers.
authored
110 In your views, you will get the following helpers:
111
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
112 resource #=> @project
113 collection #=> @projects
114 resource_class #=> Project
960671b @josevalim Added parents helpers when using polymorphic controllers.
authored
115
116 As you might expect, collection (@projects instance variable) is only available
117 on index actions.
118
e9df22c @josevalim Allow inherited resources to work just calling inherit_resources inside ...
authored
119 If for some reason you cannot inherit from InheritedResources::Base, you can
cf4b234 @josevalim Complete refactoring of respond_to.
authored
120 call inherit_resources in your controller class scope:
e9df22c @josevalim Allow inherited resources to work just calling inherit_resources inside ...
authored
121
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
122 class AccountsController < ApplicationController
123 inherit_resources
124 end
e9df22c @josevalim Allow inherited resources to work just calling inherit_resources inside ...
authored
125
5bba068 @josevalim Wrap everything before new release.
authored
126 == Overwriting defaults
f0b92a4 @josevalim First commit! :)
authored
127
d201f1f @josevalim More README cleanup.
authored
128 Whenever you inherit from InheritedResources, several defaults are assumed.
f6fb96a @josevalim Updated README and moving to 0.7.0
authored
129 For example you can have an AccountsController to account management while the
130 resource is an User:
f0b92a4 @josevalim First commit! :)
authored
131
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
132 class AccountsController < InheritedResources::Base
133 defaults :resource_class => User, :collection_name => 'users', :instance_name => 'user'
134 end
f0b92a4 @josevalim First commit! :)
authored
135
a3a735a @josevalim Decoupled routes names from collection name and instance name to allow m...
authored
136 In the case above, in your views you will have @users and @user variables, but
137 the routes used will still be accounts_url and account_url. If you plan also to
138 change the routes, you can use :route_collection_name and :route_instance_name.
139
7def86b @josevalim Namespaced controllers now work out of the box (no configuration needed)...
authored
140 Namespaced controllers work out of the box, but if you need to specify a
141 different route prefix, you can do the following:
b18bcd9 @josevalim Added support to namespaced routes with defaults :route_prefix.
authored
142
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
143 class Administrators::PeopleController < InheritedResources::Base
144 defaults :route_prefix => 'admin'
145 end
b18bcd9 @josevalim Added support to namespaced routes with defaults :route_prefix.
authored
146
d201f1f @josevalim More README cleanup.
authored
147 Then your named routes will be: 'admin_people_url', 'admin_person_url' instead
148 of 'administrators_people_url' and 'administrators_person_url'.
b18bcd9 @josevalim Added support to namespaced routes with defaults :route_prefix.
authored
149
d201f1f @josevalim More README cleanup.
authored
150 If you want to customize how resources are retrieved you can overwrite
151 collection and resource methods. The first is called on index action and the
152 second on all other actions. Let's suppose you want to add pagination to your
153 projects collection:
f0b92a4 @josevalim First commit! :)
authored
154
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
155 class ProjectsController < InheritedResources::Base
156 protected
157 def collection
2e72c0e Pagination example working for will_paginate
Paul Campbell authored
158 @projects ||= end_of_association_chain.paginate(:page => params[:page])
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
159 end
160 end
f0b92a4 @josevalim First commit! :)
authored
161
d201f1f @josevalim More README cleanup.
authored
162 The end_of_association_chain returns your resource after nesting all associations
f6fb96a @josevalim Updated README and moving to 0.7.0
authored
163 and scopes (more about this below).
f0b92a4 @josevalim First commit! :)
authored
164
d201f1f @josevalim More README cleanup.
authored
165 InheritedResources also introduces another method called begin_of_association_chain.
166 It's mostly used when you want to create resources based on the @current_user and
0f7bfd5 @josevalim Allow interpolation options to be set in the application controller.
authored
167 you have urls like "account/projects". In such cases, you have to do
249d2ce @josevalim Added support for "success/failure blocks" (thanks grosser for the idea!...
authored
168 @current_user.projects.find or @current_user.projects.build in your actions.
d201f1f @josevalim More README cleanup.
authored
169
249d2ce @josevalim Added support for "success/failure blocks" (thanks grosser for the idea!...
authored
170 You can deal with it just doing:
f0b92a4 @josevalim First commit! :)
authored
171
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
172 class ProjectsController < InheritedResources::Base
173 protected
174 def begin_of_association_chain
175 @current_user
176 end
177 end
f0b92a4 @josevalim First commit! :)
authored
178
5bba068 @josevalim Wrap everything before new release.
authored
179 == Overwriting actions
f0b92a4 @josevalim First commit! :)
authored
180
181 Let's suppose that after destroying a project you want to redirect to your
182 root url instead of redirecting to projects url. You just have to do:
183
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
184 class ProjectsController < InheritedResources::Base
185 def destroy
186 super do |format|
187 format.html { redirect_to root_url }
188 end
189 end
190 end
191
192 You are opening your action and giving the parent action a new behavior. On
193 the other hand, I have to agree that calling super is not very readable. That's
194 why all methods have aliases. So this is equivalent:
195
196 class ProjectsController < InheritedResources::Base
197 def destroy
198 destroy! do |format|
199 format.html { redirect_to root_url }
200 end
201 end
202 end
f0b92a4 @josevalim First commit! :)
authored
203
3b41204 @josevalim Allow blocks with arity equal zero to be given as redirect_url
authored
204 Even more, since most of the times when you change a create, update or destroy
a99ce3b @josevalim More documentation.
authored
205 action is because you want to to change to where it redirects, a shortcut is
206 provided. So you can do:
207
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
208 class ProjectsController < InheritedResources::Base
209 def destroy
210 destroy!{ root_url }
211 end
212 end
a99ce3b @josevalim More documentation.
authored
213
f0b92a4 @josevalim First commit! :)
authored
214 Now let's suppose that before create a project you have to do something special
215 but you don't want to create a before filter for it:
216
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
217 class ProjectsController < InheritedResources::Base
218 def create
219 @project = Project.new(params[:project])
220 @project.something_special!
221 create!
222 end
223 end
f0b92a4 @josevalim First commit! :)
authored
224
f6fb96a @josevalim Updated README and moving to 0.7.0
authored
225 Yes, that simple! The nice part is since you already set the instance variable
226 @project, it will not build a project again.
f0b92a4 @josevalim First commit! :)
authored
227
579fc66 @josevalim New gem version 0.2.0 and pushed documentation about success/failure blo...
authored
228 Before we finish this topic, we should talk about one more thing: "success/failure
229 blocks". Let's suppose that when we update our project, in case of failure, we
230 want to redirect to the project url instead of re-rendering the edit template.
231
232 Our first attempt to do this would be:
233
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
234 class ProjectsController < InheritedResources::Base
235 def update
236 update! do |format|
237 unless @project.errors.empty? # failure
238 format.html { redirect_to project_url(@project) }
239 end
240 end
579fc66 @josevalim New gem version 0.2.0 and pushed documentation about success/failure blo...
authored
241 end
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
242 end
579fc66 @josevalim New gem version 0.2.0 and pushed documentation about success/failure blo...
authored
243
d201f1f @josevalim More README cleanup.
authored
244 Looks to verbose, right? We can actually do:
579fc66 @josevalim New gem version 0.2.0 and pushed documentation about success/failure blo...
authored
245
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
246 class ProjectsController < InheritedResources::Base
247 def update
248 update! do |success, failure|
249 failure.html { redirect_to project_url(@project) }
250 end
251 end
252 end
579fc66 @josevalim New gem version 0.2.0 and pushed documentation about success/failure blo...
authored
253
2aa1762 @josevalim Updated README
authored
254 Much better! So explaining everything: when you give a block which expects one
579fc66 @josevalim New gem version 0.2.0 and pushed documentation about success/failure blo...
authored
255 argument it will be executed in both scenarios: success and failure. But If you
256 give a block that expects two arguments, the first will be executed only in
257 success scenarios and the second in failure scenarios. You keep everything
258 clean and organized inside the same action.
259
5bba068 @josevalim Wrap everything before new release.
authored
260 == Some DSL
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
261
262 For those DSL lovers, InheritedResources won't leave you alone. You can overwrite
263 your success/failure blocks straight from your class binding. For it, you just
6356a50 @josevalim Bring dual blocks back to destroy action.
authored
264 need to add a DSL module to your application controller:
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
265
266 class ApplicationController < ActionController::Base
267 include InheritedResources::DSL
268 end
269
270 And then you can rewrite the last example as:
271
272 class ProjectsController < InheritedResources::Base
273 update! do |success, failure|
274 failure.html { redirect_to project_url(@project) }
275 end
276 end
277
5bba068 @josevalim Wrap everything before new release.
authored
278 == Belongs to
f0b92a4 @josevalim First commit! :)
authored
279
280 Finally, our Projects are going to get some Tasks. Then you create a
281 TasksController and do:
282
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
283 class TasksController < InheritedResources::Base
284 belongs_to :project
285 end
f0b92a4 @josevalim First commit! :)
authored
286
287 belongs_to accepts several options to be able to configure the association.
c1eb780 @josevalim First scratch at scopes implementation.
authored
288 For example, if you want urls like /projects/:project_title/tasks, you can
289 customize how InheritedResources find your projects:
f0b92a4 @josevalim First commit! :)
authored
290
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
291 class TasksController < InheritedResources::Base
292 belongs_to :project, :finder => :find_by_title!, :param => :project_title
293 end
f0b92a4 @josevalim First commit! :)
authored
294
49ff641 @josevalim Telling more about belongs_to options in the README
authored
295 It also accepts :route_name, :parent_class and :instance_name as options.
c1eb780 @josevalim First scratch at scopes implementation.
authored
296 Check the lib/inherited_resources/class_methods.rb for more.
f0b92a4 @josevalim First commit! :)
authored
297
5bba068 @josevalim Wrap everything before new release.
authored
298 == Nested belongs to
f0b92a4 @josevalim First commit! :)
authored
299
300 Now, our Tasks get some Comments and you need to nest even deeper. Good
301 practices says that you should never nest more than two resources, but sometimes
302 you have to for security reasons. So this is an example of how you can do it:
303
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
304 class CommentsController < InheritedResources::Base
305 nested_belongs_to :project, :task
306 end
f0b92a4 @josevalim First commit! :)
authored
307
872ffaf @josevalim More typos fixed in the README (Thanks to Alexei again!)
authored
308 If you need to configure any of these belongs to, you can nest them using blocks:
f0b92a4 @josevalim First commit! :)
authored
309
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
310 class CommentsController < InheritedResources::Base
311 belongs_to :project, :finder => :find_by_title!, :param => :project_title do
312 belongs_to :task
313 end
314 end
f0b92a4 @josevalim First commit! :)
authored
315
d201f1f @josevalim More README cleanup.
authored
316 Warning: calling several belongs_to is the same as nesting them:
317
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
318 class CommentsConroller < InheritedResources::Base
319 belongs_to :project
320 belongs_to :task
321 end
d201f1f @josevalim More README cleanup.
authored
322
323 In other words, the code above is the same as calling nested_belongs_to.
324
5bba068 @josevalim Wrap everything before new release.
authored
325 == Polymorphic belongs to
f0b92a4 @josevalim First commit! :)
authored
326
dd394d7 @josevalim Remove useless features and bump tiny.
authored
327 We can go even further. Let's suppose our Projects can now have Files, Messages
328 and Tasks, and they are all commentable. In this case, the best solution is to
329 use polymorphism:
f0b92a4 @josevalim First commit! :)
authored
330
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
331 class CommentsController < InheritedResources::Base
332 belongs_to :task, :file, :message, :polymorphic => true
333 # polymorphic_belongs_to :task, :file, :message
334 end
f0b92a4 @josevalim First commit! :)
authored
335
336 You can even use it with nested resources:
337
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
338 class CommentsController < InheritedResources::Base
339 belongs_to :project do
340 belongs_to :task, :file, :message, :polymorphic => true
341 end
342 end
f0b92a4 @josevalim First commit! :)
authored
343
dd394d7 @josevalim Remove useless features and bump tiny.
authored
344 The url in such cases can be:
345
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
346 /project/1/task/13/comments
347 /project/1/file/11/comments
348 /project/1/message/9/comments
dd394d7 @josevalim Remove useless features and bump tiny.
authored
349
f0b92a4 @josevalim First commit! :)
authored
350 When using polymorphic associations, you get some free helpers:
351
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
352 parent? #=> true
353 parent_type #=> :task
354 parent_class #=> Task
355 parent #=> @task
f0b92a4 @josevalim First commit! :)
authored
356
a8751f4 @josevalim Change README to talk about rspec bug and polymorphic associations.
authored
357 Right now, Inherited Resources is limited and does not allow you
358 to have two polymorphic associations nested.
359
5bba068 @josevalim Wrap everything before new release.
authored
360 == Optional belongs to
8b5b2c5 @josevalim Added :optional information on README
authored
361
dd394d7 @josevalim Remove useless features and bump tiny.
authored
362 Later you decide to create a view to show all comments, independent if they belong
363 to a task, file or message. You can reuse your polymorphic controller just doing:
8b5b2c5 @josevalim Added :optional information on README
authored
364
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
365 class ProjectsController < InheritedResources::Base
366 belongs_to :task, :file, :message, :optional => true
367 # optional_belongs_to :task, :file, :message
368 end
8b5b2c5 @josevalim Added :optional information on README
authored
369
370 This will handle all those urls properly:
371
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
372 /comment/1
373 /tasks/2/comment/5
374 /files/10/comment/3
375 /messages/13/comment/11
8b5b2c5 @josevalim Added :optional information on README
authored
376
377 This is treated as a special type of polymorphic associations, thus all helpers
378 are available. As you expect, when no parent is found, the helpers return:
379
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
380 parent? #=> false
381 parent_type #=> nil
382 parent_class #=> nil
383 parent #=> nil
8b5b2c5 @josevalim Added :optional information on README
authored
384
5bba068 @josevalim Wrap everything before new release.
authored
385 == Singletons
f0b92a4 @josevalim First commit! :)
authored
386
387 Now we are going to add manager to projects. We say that Manager is a singleton
388 resource because a Project has just one manager. You should declare it as
389 has_one (or resource) in your routes.
390
391 To declare an association as singleton, you just have to give the :singleton
392 option.
393
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
394 class ManagersController < InheritedResources::Base
395 belongs_to :project, :singleton => true
396 # singleton_belongs_to :project
397 end
f0b92a4 @josevalim First commit! :)
authored
398
399 It will deal with everything again and hide the action :index from you.
400
5bba068 @josevalim Wrap everything before new release.
authored
401 == URL Helpers
f0b92a4 @josevalim First commit! :)
authored
402
5e9177d @josevalim Going to 0.4.1!
authored
403 When you use InheritedResources it creates some URL helpers.
404 And they handle everything for you. :)
f0b92a4 @josevalim First commit! :)
authored
405
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
406 # /posts/1/comments
407 resource_url # => /posts/1/comments/#{@comment.to_param}
408 resource_url(comment) # => /posts/1/comments/#{comment.to_param}
409 new_resource_url # => /posts/1/comments/new
410 edit_resource_url # => /posts/1/comments/#{@comment.to_param}/edit
411 edit_resource_url(comment) #=> /posts/1/comments/#{comment.to_param}/edit
412 collection_url # => /posts/1/comments
5bba068 @josevalim Wrap everything before new release.
authored
413 parent_url # => /posts/1
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
414
415 # /projects/1/tasks
416 resource_url # => /projects/1/tasks/#{@task.to_param}
417 resource_url(task) # => /projects/1/tasks/#{task.to_param}
418 new_resource_url # => /projects/1/tasks/new
419 edit_resource_url # => /projects/1/tasks/#{@task.to_param}/edit
420 edit_resource_url(task) # => /projects/1/tasks/#{task.to_param}/edit
421 collection_url # => /projects/1/tasks
5bba068 @josevalim Wrap everything before new release.
authored
422 parent_url # => /projects/1
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
423
424 # /users
425 resource_url # => /users/#{@user.to_param}
426 resource_url(user) # => /users/#{user.to_param}
427 new_resource_url # => /users/new
428 edit_resource_url # => /users/#{@user.to_param}/edit
429 edit_resource_url(user) # => /users/#{user.to_param}/edit
430 collection_url # => /users
5bba068 @josevalim Wrap everything before new release.
authored
431 parent_url # => /
5e9177d @josevalim Going to 0.4.1!
authored
432
433 Those urls helpers also accepts a hash as options, just as in named routes.
434
4776927 @josevalim Added class method DSL, fixed polymorphic helpers message and updated RE...
authored
435 # /projects/1/tasks
436 collection_url(:page => 1, :limit => 10) #=> /projects/1/tasks?page=1&limit=10
f0b92a4 @josevalim First commit! :)
authored
437
cf4b234 @josevalim Complete refactoring of respond_to.
authored
438 In polymorphic cases, you can also give the parent as parameter to collection_url.
439
5e9177d @josevalim Going to 0.4.1!
authored
440 Another nice thing is that those urls are not guessed during runtime. They are
f0b92a4 @josevalim First commit! :)
authored
441 all created when your application is loaded (except for polymorphic
442 associations, that relies on Rails polymorphic_url).
443
c25da84 @josevalim Bump tiny.
authored
444 == Bugs and Feedback
f0b92a4 @josevalim First commit! :)
authored
445
2f20cec @josevalim Added link to the mailing list in README.
authored
446 If you discover any bugs or want to drop a line, join us in the mailing list:
447
448 http://groups.google.com/group/inherited_resources
f0b92a4 @josevalim First commit! :)
authored
449
35467fa @josevalim Updated README
authored
450 Copyright (c) 2009 José Valim http://blog.plataformatec.com.br
9207c29 @josevalim Remove has_scope from core.
authored
451 See the attached MIT License.
Something went wrong with that request. Please try again.