# Newbie question about routing with forms & db items

**URL:** <https://www.ruby-forum.com/t/newbie-question-about-routing-with-forms-db-items/127854>\
**Category:** Rails\
**Created:** [February 1, 2008, 9:19pm UTC](https://www.ruby-forum.com/t/newbie-question-about-routing-with-forms-db-items/127854 "2008-02-01T21:19:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 1, 2008, 9:19pm UTC](https://www.ruby-forum.com/t/newbie-question-about-routing-with-forms-db-items/127854/1 "2008-02-01T21:19:23Z")

</div>

Hi

I am trying to do my 1st ror application. I would like to make web  
form routing on this manner:

1st page: [http://myurl/start](http://myurl/start)

this page will read information from mysql database and show items as  
web form

1. on [http://myurl/start](http://myurl/start) page is submit button which submits all form  
items to action select

2. action select gives out new form which have all information from  
the start page and it will create  
new web form with some additional items read from the database (based  
on the user input given on start page).

3. select web form page will then submit all data back to database

What I have done now is:

on routes.rb I have defined

map.resources :imitems

(this will handle all basic database functions ie. edit new item,  
delete etc)

then I have added 2 new actions on routes.rb table: (which use imitems  
database schema)

# /imitems/start

# 

map.resources :imitems, :collection =\> { :start =\> :get }  
map.resources :imitems, :new =\> { :start =\> :any, :start =\> :post }

# 

# 

# /imitems/select

# 

map.resources :imtems, :collection =\> { :select =\> :get }  
map.resources :imitems, :new =\> { :select =\> :any, :select =\> :post }  
map.resources :imitems, :controller =\> “imitems”, :path\_prefix =\> “/  
select/:category\_id”, :name\_prefix =\> “select\_”

now on controller for imitems I have defined actions for start and  
select like this:

class ImitemsController \< ApplicationController

def start  
@imitems = Imitem.find(:all)  
end

def select  
@imitems = Imitem.find(:all)  
@imitem = Imitem.find(params[:id])  
end

and start.html.erb looks like this:

\<% for imitem in @imitems %\>  
\<%= h imitem.grpname %\>  
\<%= link\_to ‘Select Group’, :action =\> ‘select’, :id =\> imitem %\>  
\<% end %\>

and select.html.erb looks like this:

\<% form\_for(@imitem) do |f| %\>  
**Group Name** \<%= f.text\_field :grpname %\>  
\<% end %\>

all this seems to work fine but I have some unclarity about why items  
on [http://myurl/start](http://myurl/start) page  
shows all links eg. [Select Group](https://www.ruby-forum.com/imitems/select/8) I  
though that those links  
would show up as: [Select Group](https://www.ruby-forum.com/imitems/8/select)

Also does those definitions on routes.rb makes any sense ? and why on  
select action I was forced  
to define

```
@imitems = Imitem.find(:all)
@imitem = Imitem.find(params[:id])

```

ie. I would have though that @imitem = Imitem.find(params[:id]) will  
give out ID for the item selected on start  
page and then it would use this ID to find out information on select  
page. Well it wont work unless I put  
that @imitems = Imitem.find(:all) definition for select action on  
controller ImitemsController.

Does this makes any sense and is there some definition which you can  
use to make  
all available actions (POST,GET,PUT etc) available without making one  
line per each  
item on routes.rb file ?

Thank You
