Your SlideShare is downloading. ×
Simple restfull app_s
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Simple restfull app_s

790
views

Published on


0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
790
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Simple Restfull apps with inherited resources
  • 2. REST IMAGE
  • 3. rails 3: Gemfile : gem inherited_resources bundle installrails 2.3.x: gem install inherited_resources --version=1.0.6 Inherited resources https://github.com/josevalim/inherited_resources.git
  • 4. 1. class ProjectController < InheritedResources::Base2. class ProjectController < ApplicationController inherit_resources ... end resource #=> @project collection #=> @projects resource_class #=> Projectclass ProjectController < InheritedResources::Base defaults :resource_class => Market, :collection_name => marketsend
  • 5. class ProjectController < InheritedResources::Base def collection @projects ||= end_of_association_chain.paginate(...) endendclass ProjectController < InheritedResources::Base def resource ... endend
  • 6. Respond To #=> ... respond_to :xml, :html, :json respond_to :js, :only => :create respond_to :iphone, :except => [:edit, :update] ...And actions #=> class ProjectsController < InheritedResources::Base actions :index, :show, :create, :update # or actions :all, :except => [:update, :destroy] end
  • 7. Overwriting actions class ProjectController < InheritedResources::Base def destroy super do |format| format.html { redirect_to root_url } end end end class ProjectController < InheritedResources::Base def destroy destroy!{ root_url } end end
  • 8. Overwriting actions class ProjectController < InheritedResources::Base def create create!(:notice => "project created" ) { root_url } end end class ProjectController < InheritedResources::Base def create @project = Project.new(params[:project]) @project.something_special create! # or super end end
  • 9. Overwriting actions. Errors. class ProjectController < InheritedResources::Base def update update! do |format| unless @project.errors.empty? format.html { projects_url( @project ) } end end end end class ProjectController < InheritedResources::Base def update update! do |success, failure| failure.html { projects_url( @project ) } end end end
  • 10. belongs_to :project, :finder => :find_by_title!, :param => :project_title, :polymorphic => true, :singleton => true
  • 11. Decent Exposure class ArticlesController < ApplicationController private def articles @articles ||= Article.order(:name) end helper_method :articles def article @article ||= #some else get or new end helper_method :article end
  • 12. Decent Exposure class ArticlesController < ApplicationController expose(:article) expose(:articles) { Article.order(:name) } end
  • 13. RespondersInheritedResources.flash_keys = [ :success, :failure ]flash: actions: create: notice: "%{resource_name} was successfully created." update: notice: "%{resource_name} was successfully updated." destroy: notice: "%{resource_name} was successfully destroyed." alert: "%{resource_name} could not be destroyed."