• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Simple restfull app_s
 

Simple restfull app_s

on

  • 895 views

 

Statistics

Views

Total Views
895
Views on SlideShare
895
Embed Views
0

Actions

Likes
1
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Simple restfull app_s Simple restfull app_s Presentation Transcript

    • Simple Restfull apps with inherited resources
    • REST IMAGE
    • 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
    • 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
    • class ProjectController < InheritedResources::Base def collection @projects ||= end_of_association_chain.paginate(...) endendclass ProjectController < InheritedResources::Base def resource ... endend
    • 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
    • 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
    • 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
    • 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
    • belongs_to :project, :finder => :find_by_title!, :param => :project_title, :polymorphic => true, :singleton => true
    • 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
    • Decent Exposure class ArticlesController < ApplicationController expose(:article) expose(:articles) { Article.order(:name) } end
    • 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."