Passing id in multi part form

Hi Guys,

I’m building an application that allows users to first fill in details
of a recent trip to the gym, once they click submit these details are
saved to a database table and redirects to a form that lets them input
the exercises they carried out and saves them in a second table.

I need to know how to pass the id of the update to the second form, my
controller for the update currently looks like this:

def update
@update = Update.find(params[:id])
if @update.update_attributes(params[:update])
flash[:notice] = ‘Update was successfully updated.’
redirect_to :action => ‘show’, :id => @update
else
render :action => ‘edit’
end
end

the redirect works fine, I’m pretty certain the :id=> is completely
wrong but I’m not sure how to go about this…

cheers,
Lee.

Lee, try:

redirect_to :action => ‘show’, :id => @update.id

or, since it’s still on the params:

redirect_to :action => ‘show’, :id => params[:id]

Or, if you are using RESTful routes, you can just do:

redirect_to @update

And that will default to the show action with the @update’s ID.

Another thing to remember: if you need to pass data back and forth
between requests, that’s one of the things the session hash is good
for:

Action #1:
session[:foo] = “bar”

Action #2:

foo = session[:foo] # => foo = “bar”

HTH!

-Danimal

On Apr 15, 4:15 am, Lee F. [email protected]

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