Help with session

Hi all,

I have a app with the /tests/new location which renders the add new
form. This all works perfectly so when i fill the form in it goes
straight into the db but i want the form to store the data in
session[:whateverfield] i.e.

session[:id], session[:title], session[:name], etc

Then pass this the session values to display on a preview info page.
Which then the user can edit the session. Once the form is ok then it
can be submitting to the db.

So i guess the form i have doesn’t need to be changed due to the fields
i need are there already but obviously when i press submit button it add
the info to the db and not the session, is there something i have to
change i.e. the form_for link etc.

Any help will be great

Thanks

On 21 April 2012 12:03, Paul Na [email protected] wrote:

Which then the user can edit the session. Once the form is ok then it
can be submitting to the db.

So i guess the form i have doesn’t need to be changed due to the fields
i need are there already but obviously when i press submit button it add
the info to the db and not the session, is there something i have to
change i.e. the form_for link etc.

Possibly you want separate controller actions, one that just saves it
in the session and one that saves it in the db. Either that or extend
the existing actions to do one or the other as appropriate.

Colin

Hi Colin,

Sorry i understand bits but I’m still new at rails. I see the form
action is /tests and the form POSTs i.e.

 tests   GET        /tests(.:format)              tests#index
           POST      /tests(.:format)              tests#create 

<---- this one
POST /tests(.:format) tests#save
<-------- new one
new_test GET /tests/new(.:format) tests#new
edit_test GET /tests/:id/edit(.:format) test#edit
test GET /tests/:id(.:format) tests#show
PUT /tests/:id(.:format) tests#update
DELETE /tests/:id(.:format) tests#destroy
root /
tests#index

So i can create a action save which saves to the session, then the
preview just retrieves the session values and links to edit, continue
then the last one gives a page to submit the session values to the db
with tests#create.

Does this sound ok? Also the above routes are not in the routes.rb so
where are these stored?

Edit: Do you know of any good session tutorials?

Thanks

On 21 April 2012 12:52, Paul Na [email protected] wrote:

<-------- new one
preview just retrieves the session values and links to edit, continue
then the last one gives a page to submit the session values to the db
with tests#create.

Does this sound ok?

Sounds good to me

Also the above routes are not in the routes.rb so
where are these stored?

I think they probably /are/ in routes.rb, you just don’t realise it.
Have a look at the Rails Guide on Routing.

Colin

On 21/04/2012, Paul Na [email protected] wrote:

All i have in my routes.rb are:

Tests::Application.routes.draw do

resources :tests

Precisely. Look at the Rails Guide to see what that means.

Colin


gplus.to/clanlaw

Colin L. wrote in post #1057707:

On 21 April 2012 12:52, Paul Na [email protected] wrote:

<-------- new one
preview just retrieves the session values and links to edit, continue
then the last one gives a page to submit the session values to the db
with tests#create.

Does this sound ok?

Sounds good to me

cool :slight_smile:

Also the above routes are not in the routes.rb so
where are these stored?

I think they probably /are/ in routes.rb, you just don’t realise it.
Have a look at the Rails Guide on Routing.

Colin

All i have in my routes.rb are:

Tests::Application.routes.draw do

resources :tests

root :to => ‘tests#index’

end

and that is it. I have had a brief look at it.

Thanks for you help

Tests::Application.routes.draw do

resources :tests

Precisely. Look at the Rails Guide to see what that means.

Right ok i have got the new action defined with:

resources :tests do
post ‘save’, :on => :collection
end

which defines as /tests/save => tests#save

then i rake routes and its show up in the routes now :), but the only
problem i couldn’t see information unless i’m bind about how to set the
form to now submit with the new /tests/save action and not tests#create.

Many thanks

I presume you are using form_for to generate the form. It takes a
:url option which you can use to specify a named route. Have a look
at the docs for form_for. When you are trying to get it to work look
at the html of the page to check it is right. (View > Page Source or
similar in your browser).

Yes i am using form_for. Arh Ok colin i will check that out. Thanks

On 21 April 2012 17:47, Paul Na [email protected] wrote:

resources :tests do
post ‘save’, :on => :collection
end

which defines as /tests/save => tests#save

then i rake routes and its show up in the routes now :), but the only
problem i couldn’t see information unless i’m bind about how to set the
form to now submit with the new /tests/save action and not tests#create.

I presume you are using form_for to generate the form. It takes a
:url option which you can use to specify a named route. Have a look
at the docs for form_for. When you are trying to get it to work look
at the html of the page to check it is right. (View > Page Source or
similar in your browser).

Colin