Absolute beginner here - sorry if this the answer is obvious - but i don't know enough to search effectively ! I've started from generated scaffolding. There are now two routes to a page that adds a 'contact' . When a contact is successfully added I would like the system to return to the page that called it . When I go into the add contact page I'm passing a parameter to indicate where its come from : <%=button_to 'New Contact ', :controller => "contacts" ,:action => 'new' ,:from_folder=>'1'%> gives a url of http://localhost:3000/contacts/new?from_folder=1
I've changed the contacts controller create method as follows def create @contact = Contact.new(params[:contact]) @temp = params[:from_folder] # @temp = 1 if @contact.save flash[:notice] = 'Contact was successfully created.' if @temp == '1' redirect_to :controller => 'folders' ,:action => 'new' else redirect_to :controller => 'chs' ,:action => 'index' end else render :action => 'new' end end
BUT this doesnt pick up the params[:from_folder] . Firstly is this a sensible way to approach this ? or is there another way ? secondly - why isnt the controller seeing the parameter ? The new contact form is still using
<%= start_form_tag :action => 'create' %> <%= render :partial => 'form' %> <%= submit_tag "Create" %>
Thanks in advance
Kath