README.rdoc in inherited_resources-0.9.5 vs README.rdoc in inherited_resources-1.0.pre

- old
+ new

@@ -1,11 +1,7 @@ -Inherited Resources -License: MIT -Version: 0.9.2 +== Inherited Resources -== Description - 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. Plus, making your controllers follow a pattern, it helps you to write better @@ -14,24 +10,57 @@ http://akitaonrails.com/2009/09/01/screencast-real-thin-restful-controllers-with-inherited-resources Inherited Resources is tested and compatible with Rails 2.2.x and Rails 2.3.x. -keywords: resources, controller, singleton, belongs_to, polymorphic, named_scope and I18n - == Installation -Install Inherited Resources is very easy. It is stored in GitHub, so just run -the following: +Inherited Resources is available as gem on Gemcutter, so just run the following: - gem sources -a http://gemcutter.org sudo gem install inherited_resources If you want it as plugin, just do: script/plugin install git://github.com/josevalim/inherited_resources.git +== Inherited Resources 1.0.pre + +Inherited Resources is close to 1.0 version. A couple things changed, +so be sure to read the following sections if you want to try it out: + +=== HasScope + +In Inherited Resources 1.0, has_scope is not part of its core anymore. +However, if you are using has_scope in your application, Inherited Resources +will handle all the required hooks automatically. + +has_scope gem is available at: + + http://github.com/plataformatec/has_scope + +And can be installed as: + + sudo gem install has_scope + +=== Responders + +In Inherited Resources 1.0, responders are not part of its core anymore, +but is set as Inherited Resources dependency and it's used by default by +InheritedResources controllers. Be sure to check the documentation to see +how it will change your application: + + http://github.com/plataformatec/responders + +And it can be installed as: + + sudo gem install responders + +Using responders will set the flash message to :notice and :alert. You can change +that through the following configuration value: + + InheritedResources.flash_keys = [ :success, :failure ] + == Rspec known bug When used with integrate_views equals to false, rspec overwrites default_render, render and some other controller methods which makes Inherited Resources not work properly. In such cases, you have to set integrate_views to true. @@ -244,113 +273,10 @@ update! do |success, failure| failure.html { redirect_to project_url(@project) } end end -== Flash messages and I18n - -Flash messages are powered by I18n api. It checks for messages in the following -order: - - flash.controller_name.action_name.status - flash.actions.action_name.status - -If none is available, a default message in english set. In a create action -on projects controller, it will search for: - - flash.projects.create.status - flash.actions.create.status - -The status can be :notice (when the object can be created, updated -or destroyed with success) or :error (when the objecy cannot be created -or updated). - -Those messages are interpolated by using the resource class human name, which -is also localized and it means you can set: - - flash: - actions: - create: - notice: "Hooray! {{resource_name}} was successfully created!" - -It will replace {{resource_name}} by the human name of the resource class, -which is "Project" in this case. - -But sometimes, flash messages are not that simple. Sometimes you want to say -the title of the project while updating a project. Well, that's easy also: - - flash: - projects: - update: - notice: "Hooray! The project "{{project_title}}" was updated!" - -Since :project_title is not available for interpolation by default, you have -to overwrite interpolation_options. - - def interpolation_options - { :project_title => @project.title } - end - -Then you will finally have: - - "Hooray! The project "Plataforma" was updated!" - -By default, resource name is capitalized. If you want to make it lower case, you -can add to your application controller: - - def interpolation_options - { :resource_name => resource_class.human_name.downcase } - end - -Finally, if your controller is namespaced, for example Admin::ProjectsController, -the messages will be checked in the following order: - - flash.admin.projects.create.notice - flash.admin.actions.create.notice - flash.projects.create.notice - flash.actions.create.notice - -== Has Scope - -InheritedResources tries to integrate nicely with your model. In order to do so, -it also is named_scope fluent. Let's suppose our Project model with the scopes: - - class Project < ActiveRecord::Base - named_scope :featured, :conditions => { :featured => true } - named_scope :by_methodology, proc {|methodology| { :conditions => { :methodology => methodology } } } - named_scope :limit, proc{|limit| :limit => limit.to_i } - end - -Your controller: - - class ProjectsController < InheritedResources::Base - has_scope :featured, :boolean => true, :only => :index - has_scope :by_methodology - has_scope :limit, :default => 10 - end - -Then for each request: - - /projects - #=> acts like a normal request, but returning 10 projects - - /projects?featured=true - #=> calls the featured named scope and bring 10 featured projects - - /projects?featured=true&by_methodology=agile&limit=20 - #=> brings 20 featured projects with methodology agile - -You can retrieve the current scopes in use with :current_scopes method. -In the last case, it would return: - - { :featured => "true", :by_methodology => "agile", :limit => "20" } - -Finally, let's suppose you store on the session how many projects the user sees -per page. In such cases, you can give a proc as default value: - - has_scope :limit, :default => proc{|c| c.session[:limit] || 10 } - == Belongs to Finally, our Projects are going to get some Tasks. Then you create a TasksController and do: @@ -520,5 +446,6 @@ If you discover any bugs or want to drop a line, join us in the mailing list: http://groups.google.com/group/inherited_resources Copyright (c) 2009 José Valim http://blog.plataformatec.com.br +See the attached MIT License.