Topic: form_for to another controller

In another thread I found this solution:

    <% remote_form_for :document,
                       :url => { :action => documents_url(:post_type => "document", :companytool_id => @tool, :escape=> false), :multipart => true },
                       :html => { :action => documents_url(:post_type => "document", :companytool_id => @tool, :escape=> false), :multipart => true },
                       :before => "$('spinner').show()",
                       :complete => "$('spinner').hide(); $('file_field').value=''" do |f| %>

but I decided not to make it remote, but when I do this:

    <% form_for :document,
                :url => {:action => documents_url(:post_type => "document", :companytool_id => @tool, :escape=> false), :multipart => true, :controller=>"" } do |f| %>

it spits out:

<form action="/companytool/http://localhost:3000/documents?post_type=document&amp;companytool_id=1?multipart=true" method="post">

Anyone know how to get rid of the controller name in front of the url? The companytool_controller is the one I'm submitting the form from

/megl

Re: form_for to another controller

The documents_url spits out a URL string containing the controller and everything. I think what you want is this:

<% form_for :document, :url => {:post_type => "document", :companytool_id => @tool }, :multipart => true do |f| %>

Railscasts - Free Ruby on Rails Screencasts

Re: form_for to another controller

No, the form is in a page spawned by the companytool controller, and I want the post to be handled by the document controller. The code you posted spits out:

/companytool/show/2?companytool_id=2&amp;post_type=document

so it basically just reloads the page, and it doesn't help to put a :controller => "document" in there

I know I could do it the old fashioned way, but I would like to learn how the form_for works

/megl

Last edited by megl (2007-01-26 20:55:14)

Re: form_for to another controller

Oh, I see what you mean now. Try this:

% form_for :document, :url => documents_url(:post_type => "document", :companytool_id => @tool, :escape => false), :multipart => true do |f| %>

form_for should handle URLs the same way the rest of Rails does (url_for, link_to, etc.).

Railscasts - Free Ruby on Rails Screencasts

Re: form_for to another controller

Ahh - there we have it

Thanks again Ryan! You saved my day once again!

/megl