README.rdoc in inherited_resources-1.3.1 vs README.rdoc in inherited_resources-1.4.0

- old
+ new

@@ -1,13 +1,5 @@ -=== Deprecation notice - -Since Rails 3 came out, I have no longer used Inherited Resources. I have found that the -responders abstraction and custom Rails generators offer the perfect balance between -hiding and showing too much logic. That said, I suggest developers to make use of the -responders gem (at https://github.com/plataformatec/responders) and no longer use Inherited -Resources. - == Inherited Resources Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important. It makes your controllers more powerful and cleaner at the same time. @@ -132,10 +124,18 @@ class AccountsController < ApplicationController inherit_resources end +One reason to use the "inherit_resources" macro would be to ensure that your controller never responds with the html mime-type. InheritedResources::Base already responds_to :html, and the respond_to macro is strictly additive. Therefore, if you want to create a controller that, for example, responds ONLY via :js, you will have write it this way: + + class AccountsController < ApplicationController + respond_to :js + inherit_resources + end + + == Overwriting defaults Whenever you inherit from InheritedResources, several defaults are assumed. For example you can have an AccountsController for account management while the resource is a User: @@ -216,11 +216,11 @@ action you do so because you want to to change its redirect url, a shortcut is provided. So you can do: class ProjectsController < InheritedResources::Base def destroy - destroy!{ root_url } + destroy! { root_url } end end If you simply want to change the flash message for a particular action, you can pass the message to the parent action using the keys :notice and :alert (as you @@ -296,11 +296,11 @@ collection_url, parent_url (which we are going to see later), and root_url. Redirect in destroy action calculate in following order collection_url, parent_url, root_url. Example: - class ButtonsConntroller < InheritedResources::Base + class ButtonsController < InheritedResources::Base belongs_to :window actions :all, :except => [:show, :index] end This controller redirect to parent window after all CUD actions. @@ -358,11 +358,11 @@ end end Warning: calling several belongs_to is the same as nesting them: - class CommentsConroller < InheritedResources::Base + class CommentsController < InheritedResources::Base belongs_to :project belongs_to :task end In other words, the code above is the same as calling nested_belongs_to. @@ -465,11 +465,11 @@ # /posts/1/comments resource_url # => /posts/1/comments/#{@comment.to_param} resource_url(comment) # => /posts/1/comments/#{comment.to_param} new_resource_url # => /posts/1/comments/new edit_resource_url # => /posts/1/comments/#{@comment.to_param}/edit - edit_resource_url(comment) #=> /posts/1/comments/#{comment.to_param}/edit + edit_resource_url(comment) # => /posts/1/comments/#{comment.to_param}/edit collection_url # => /posts/1/comments parent_url # => /posts/1 # /projects/1/tasks resource_url # => /projects/1/tasks/#{@task.to_param} @@ -537,13 +537,23 @@ update! do |success, failure| failure.html { redirect_to project_url(@project) } end end +== Strong Parameters + +If your controller defines a method named permitted_params, Inherited Resources will call it where it would normally call params. This allows for easy integration with the strong_parameters gem: + + def permitted_params + params.permit(:widget => [:permitted_field, :other_permitted_field]) + end + +Note that this doesn't work if you use strong_parameters' require method instead of permit, because whereas permit returns the entire sanitized parameter hash, require returns only the sanitized params below the parameter you required. + == Bugs and Feedback If you discover any bugs, please describe it in the issues tracker, including Rails and Inherited Resources versions. Questions are better handled on StackOverflow. -Copyright (c) 2011 José Valim http://blog.plataformatec.com.br +Copyright (c) 2009-2012 José Valim http://blog.plataformatec.com.br See the attached MIT License.