Newbie question about routing with forms & db items

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

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

  1. on 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 page
shows all links eg. Select Group I
though that those links
would show up as: Select Group

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs