# Scaffolding and dealing with generated actions in the controllers

**URL:** <https://www.ruby-forum.com/t/scaffolding-and-dealing-with-generated-actions-in-the-controllers/151992>\
**Category:** Rails\
**Created:** [October 28, 2008, 7:28pm UTC](https://www.ruby-forum.com/t/scaffolding-and-dealing-with-generated-actions-in-the-controllers/151992 "2008-10-28T19:28:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![command0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a9adbd/32.png) [@command0](https://www.ruby-forum.com/u/command0)\
**Post date:** [October 28, 2008, 7:28pm UTC](https://www.ruby-forum.com/t/scaffolding-and-dealing-with-generated-actions-in-the-controllers/151992/1 "2008-10-28T19:28:02Z")

</div>

Hey Everyone,

I wanted to know if I could get some insight on something. I am using  
Rails 2.1.2 and for something that needs beyond basic functionality, I  
typically generate a scaffold so I don’t have to manually create  
everything and save some time. Well as you all most likely know, along  
with generating a scaffold, comes predefined actions in the controller  
that is generated, usually like show, new, create, index, etc…

The question I have regarding that is how and where are all those  
actions tied to? I know Rails 2.\* uses the REST model by default, so  
everything is resourceful. And thats fine and all, but when I want to  
do something outside of those predefined actions, it throws a fit so  
to speak.

Let me illustrate what I mean by that. So lets say I wanted to create  
a Rails app for a local brewery that has a UI frontend that would act  
as the brewery site lets say which also contains a catalogue of their  
various lagers and ales that they have for sell to take home. So I  
would create an app called brew lets say - “rails -d mysql brew”.

So the skeleton is created, but now I need a model, view, and  
controller of course. I decide this needs a bit extra functionality  
from the get go so I create a scaffold - “script/generate scaffold  
beer”. I generate a new migration for the table needed to store all  
the various products that the brewery offers - “script/generate  
migration add\_products”. I write in the fields that I want in the db  
table, and run a rake db:migrate. Everything is great.

Now I can add a couple products, and show the details of them. Great.  
But now, I want to do more than that. Now I want to be able to write  
in a mashup into the app also so maybe someone could find the place,  
so I’ll integrate google and yahoo maps in with the GeoKit plugin, and  
I want to play some videos on youtube that related the brewery  
assuming there were any, so I’d use the YouTube API using something  
like the YouTube-G plugin or something.

So now I install the plugins, and then write some methods into the  
controller to act as something like a search functionality. But now  
that say these methods are wrote, and I have a template called  
search.rhtml in my view that will generate directions to the place  
using the users remote public ip and geocoding that into coordinates,  
then pulling up any youtube videos on a sidebar that has to do with  
the place.

So I make sure everything is saved, and I fire up mongrel and test it  
out. But instead of seeing the generated html form, instead I get an  
action controller exception saying “Cannot find with ID=search” or  
something to that affect, and I get lines that describe where it is  
derived from, but it would be in the controller on the line with the  
“def show” method, containing something like @beer =  
Beer.find(params[:id]), in which is is querying for the sql id field,  
which is the primary key in the table. But because I’m trying to find  
anything but ID, it fights me tooth and nail.

So, I wanted to know if anyone really understand REST, and how  
everything ties together. I have tried to delete the  
map.resources :beers (or whatever it may be), but then it has a  
routing issue. I am but I try to do anything beyond the basic methods  
laid out in the generated controller and it throws a big fit.

Can anyone clarify this for me so I could understand it better?

---

<div class="post-metadata">

**Author:** ![command0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a9adbd/32.png) [@command0](https://www.ruby-forum.com/u/command0)\
**Post date:** [October 29, 2008, 10:32pm UTC](https://www.ruby-forum.com/t/scaffolding-and-dealing-with-generated-actions-in-the-controllers/151992/2 "2008-10-29T22:32:49Z")

</div>

Just a few guidelines so you can learn the rest on your own:

Make sure you understand the map.resources method and its  
capabilities, and especially read the part on adding custom actions  
(through the :collection, :member and :new options of map.resources):

[http://apidock.com/rails/ActionController/Resources/resources](http://apidock.com/rails/ActionController/Resources/resources)

REST actions in Rails are probably the least DRY part of the  
framework, and you’ll need to add any custom methods you add to your  
controller to config/routes.rb file as well.

Try reading the first chapter of the book Advanced Rails Recipes  
(Pragmatic Programmers) if you have access to the book, or just read  
about REST in Rails in blogs, some have useful information (though  
some others may be a bit outdated).

---

<div class="post-metadata">

**Author:** ![command0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a9adbd/32.png) [@command0](https://www.ruby-forum.com/u/command0)\
**Post date:** [October 29, 2008, 10:41pm UTC](https://www.ruby-forum.com/t/scaffolding-and-dealing-with-generated-actions-in-the-controllers/151992/3 "2008-10-29T22:41:02Z")

</div>

Also, try this:

> **[rails.info](http://guides.rails.info/routing_outside_in.html)**
>
> Ruby on Rails,Rails Tutorial,Ruby Basics,Rails 4,Bar Rails,Rail
