Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

resource_controller

> 编程语言
Open source

Rails RESTful controller abstraction plugin.

496 stars0 likes2 views
WebsiteGitHub

About

Rails RESTful controller abstraction plugin.

= Resource Controller

resource_controller makes RESTful controllers easier, more maintainable, and super readable. With the RESTful controller pattern hidden away, you can focus on what makes your controller special.

== Get It

Install it as a plugin:

script/plugin install git://github.com/giraffesoft/resource_controller.git

Or grab the source

git clone git://github.com/giraffesoft/resource_controller.git

= Usage

Creating a basic RESTful controller is as easy as...

class PostsController "show.rjs" } end

Or you can create a whole new block. This syntax destroys everything that's there, and starts again...

class ProjectsController "show.rjs" } end end

If you have a nested resource and want to redirect to the parent after create/update and destroy you can do this in the object controller

class CommentsController "show.rjs" }

  failure.wants.js { render :template => "display_errors.rjs" }
end

destroy do
  flash "You destroyed your project.  Good work."
  
  failure do
    flash "You cannot destroy that project.  Stop trying!"
    wants.js { render :template => "display_errors.rjs" }
  end
end

end

== Singleton Resource

If you want to create a singleton RESTful controller inherit from ResourceController::Singleton.

class AccountsController :options # /account/options, account is a singleton parent map.resources :users, :has_one => :image # /users/1/image, image is a singleton child

If you have the :has_many association with a singleton parent remember to override parent_object for your :has_many controller as it returns nil by default in this case.

class OptionsController {:size => 10, :current => params[:page]}) end end

Or maybe you used a permalink...

class PostsController true end

comments_controller.rb

class CommentsController :comments map.resources :products, :has_many => :comments map.resources :users, :has_many => :comments

All you have to do is that, and r_c will infer whichever relationship is present, and perform all the actions at the scope of the parent object.

=== Parent Helpers

You also get some helpers for reflecting on your parent.

parent? # => true/false is there a parent present? parent_type # => :post parent_model # => Post parent_object # => @post

=== Non-standard resource names

resource_controller supports overrides for every non-standard configuration of resources.

The most common example is where the resource has a different name than the associated model. Simply overriding the model_name helper will get resource_controller working with your model.

map.resources :tags ... class PhotoTag "somethings" ... class Tag "taggings" ... class Taggings /posts/1/comments/#{@comment.to_param} object_url(comment) # => /posts/1/comments/#{comment.to_param} edit_object_url # => /posts/1/comments/#{@comment.to_param}/edit collection_url # => /posts/1/comments

/products/1/comments

object_url # => /products/1/comments/#{@comment.to_param} object_url(comment) # => /products/1/comments/#{comment.to_param} edit_object_url # => /products/1/comments/#{@comment.to_param}/edit collection_url # => /products/1/comments

/comments

object_url # => /comments/#{@comment.to_param} object_url(comment) # => /comments/#{comment.to_param} edit_object_url # => /comments/#{@comment.to_param}/edit collection_url # => /comments

Or with namespaced, nested controllers...

/admin/products/1/options

object_url # => /admin/products/1/options/#{@option.to_param} object_url(option) # => /admin/products/1/options/#{option.to_param} edit_object_url # => /admin/products/1/options/#{@option.to_param}/edit collection_url # => /admin/products/1/options

You get the idea. Everything is automagical! All parameters are inferred.

== Credits

resource_controller was created, and is maintained by {James Golick}[http://jamesgolick.com].

== License

resource_controller is available under the {MIT License}[http://en.wikipedia.org/wiki/MIT_License]

Issues· 10 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言