# Make\_resourceful plugin

**URL:** <https://www.ruby-forum.com/t/make-resourceful-plugin/129763>\
**Category:** IT\
**Created:** [February 21, 2008, 10:56am UTC](https://www.ruby-forum.com/t/make-resourceful-plugin/129763 "2008-02-21T10:56:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gianluca\_t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d78d45/32.png) [@gianluca\_t](https://www.ruby-forum.com/u/gianluca_t)\
**Post date:** [February 21, 2008, 10:56am UTC](https://www.ruby-forum.com/t/make-resourceful-plugin/129763/1 "2008-02-21T10:56:09Z")

</div>

Ciao a tutti,

se state lavorando con rest, vi consiglio caldaemente di vedervi questo  
screencast:

> **[\#92 make\_resourceful - RailsCasts](http://railscasts.com/episodes/92-make-resourceful)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Ho provato varie alternative ma alla fine mi sono appoggiato a questo  
plugin e lo sto utilizzando alla grande…

Ho solo un dubbio, io oggi scrivo lo stesso identico codice in tutti i  
controller es.:

class CompaniesController \< ApplicationController  
make\_resourceful do  
actions :all

```
response_for :show, :new do |format|
  format.html
  format.xml { render :xml => current_object.to_xml }
end

response_for :index do |format|
  format.html
  format.xml { render :xml => current_objects.to_xml }
end

response_for :create, :update do |format|
  format.html { redirect_to objects_path }
  format.xml { head :ok }
end

response_for :create_fails, :update_fails do |format|
  format.html { render :action => 'new' }
  format.xml { render :xml => current_object.errors, :status =>

```

:unprocessable\_entity }  
end

```
response_for :destroy do |format|
  format.html { redirect_to objects_path }
  format.xml { head :ok }
end

```

end  
end

poi altro controller con dentro lo stesso codice identico, l’unica cosa  
che cambia è il belongs\_to che indica a SitesController che è figlio di  
Company:

class SitesController \< ApplicationController  
make\_resourceful do  
actions :all  
belongs\_to :company

```
response_for :show, :new do |format|
  format.html
  format.xml { render :xml => current_object.to_xml }
end

response_for :index do |format|
  format.html
  format.xml { render :xml => current_objects.to_xml }
end

response_for :create, :update do |format|
  format.html { redirect_to objects_path }
  format.xml { head :ok }
end

response_for :create_fails, :update_fails do |format|
  format.html { render :action => 'new' }
  format.xml { render :xml => current_object.errors, :status =>

```

:unprocessable\_entity }  
end

```
response_for :destroy do |format|
  format.html { redirect_to objects_path }
  format.xml { head :ok }
end

```

end  
end

Alla faccia del DRY !!!

Ho provato a creare un controller di base (BaseController) in cui metto  
il metodo make\_resourceful con tutte le sue direttive e poi  
CompaniesController che estende BaseController ma non ci riesco, in  
CompaniesController ottengo il seguente errore:

NoMethodError (undefined method `make\_resourceful’ for  
BaseController:Class):

|app/controllers/base\_controller.rb:7|  
|app/controllers/companies\_controller.rb:1|  
||  
Qualche idea ?  
||  
PS: sto facendo una discreta esperienza su Rest / nested resources,  
aiuto volentieri se ne avete bisogno…  
||

---

<div class="post-metadata">

**Author:** ![gianluca\_t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d78d45/32.png) [@gianluca\_t](https://www.ruby-forum.com/u/gianluca_t)\
**Post date:** [February 21, 2008, 11:49am UTC](https://www.ruby-forum.com/t/make-resourceful-plugin/129763/2 "2008-02-21T11:49:54Z")

</div>

Ciao a tutti,

> se state lavorando con rest, vi consiglio caldaemente di vedervi questo  
> screencast:
> 
> [#92 make\_resourceful - RailsCasts](http://railscasts.com/episodes/92)
> 
> Ho provato varie alternative ma alla fine mi sono appoggiato a questo  
> plugin e lo sto utilizzando alla grande…  
> [http://lists.ruby-it.org/mailman/listinfo/ml](http://lists.ruby-it.org/mailman/listinfo/ml)

Tra le varie alternative hai provato anche

[http://jamesgolick.com/2007/10/19/introducing-resource\_controller-focus-on-what-makes-your-controller-special](http://jamesgolick.com/2007/10/19/introducing-resource_controller-focus-on-what-makes-your-controller-special)

È un po’ meglio IMO. ha anche un generator…

---

<div class="post-metadata">

**Author:** ![gianluca\_t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d78d45/32.png) [@gianluca\_t](https://www.ruby-forum.com/u/gianluca_t)\
**Post date:** [February 21, 2008, 2:59pm UTC](https://www.ruby-forum.com/t/make-resourceful-plugin/129763/3 "2008-02-21T14:59:32Z")

</div>

giovanni lion ha scritto:

> > 
> 
> [http://lists.ruby-it.org/mailman/listinfo/ml](http://lists.ruby-it.org/mailman/listinfo/ml)

A dire il vero ero partito con resource\_controller ma quando è stato il  
momento di eseguire render :xml =\> current\_objects.to\_xml non so per  
quale motivo voleva a tutti i costi un template .xml.erb e non avevo  
alcuna intenzione di creare 2 template (index/show) per ogni entità,  
quindi l’ho scartato… (make\_resourceful esegue il render dell’xml  
diretto senza che sia necessario passare obbligatoriamente per un  
template)…

BTW: anche make\_resourceful ha il suo generator e al momento gestisce  
controller con belongs\_to polimorfici e associazioni has\_one (man mano  
che passa il tempo mi sembra che siano sempre + simili…)
