@trainee is an instance of User class
my form partial code :
<% form_for :@trainee, :html => {:class =>
''generalform''} do |form| %>
	<%= render :partial => "form", :object => form %>
	 <%= form.submit "Register", :class => ''go''
%> <%= link_to
''Cancel'', trainees_path %>
<% end %>
the generated html is obviously :
<form id="new_user" class="generalform"
method="post" action="/users">
but I would like to send it to a trainee_controller  (rather than to
user_controller... )
(don''t want to subclass, I am using roles, and a trainee is a user
with ''trainee'' role
is it possible ?if yes, how should I proceed ?
many thanks ba
erwin
2009/10/10 Erwin <yves_dufour-ee4meeAH724@public.gmane.org>:> > @trainee is an instance of User class > > my form partial code : > > <% form_for :@trainee, :html => {:class => ''generalform''} do |form| %> > <%= render :partial => "form", :object => form %> > <%= form.submit "Register", :class => ''go'' %> <%= link_to > ''Cancel'', trainees_path %> > <% end %> > > the generated html is obviously : > <form id="new_user" class="generalform" method="post" action="/users"> > > but I would like to send it to a trainee_controller (rather than to > user_controller... ) > > (don''t want to subclass, I am using roles, and a trainee is a user > with ''trainee'' role > > is it possible ?if yes, how should I proceed ? >Have a look at the docs for form_for, the :url option will let you do this. Colin
Cris Shupp
2009-Oct-10  18:18 UTC
Re: form_for url.. how to send data to another controller
Erwin,
If I understand what you are trying to do then I was trying to solve a 
similar but lesser problem.  How to send form data from one method in a 
controller to another method in the same controller Iit does seem to 
work for your case though).  Here is a sample erb:
gather.html.erb
<h1>Gathering transient data</h1>
<% form_tag(''transient/show'') do %><!--sends to the
show method of the
transient controller-->
  <p>
    <b>First Name</b><br />
  <%= text_field_tag "firstname", TransientData.firstname %>
  <br/><b>Last Name</b><br />
  <%= text_field_tag "lastname", TransientData.lastname %>
  <%= submit_tag "Submit" %>
  </p>
<%end%>
show.html.erb
<h1>Gathering transient data</h1>
<% form_tag(''/transient/gather'')  do%> <!--and back
to gather-->
  <p>
    <b>First Name</b><br />
  <%= TransientData.firstname %>
  <br/><b>Last Name</b><br />
  <%= TransientData.lastname %>
  <%= submit_tag "Submit" %>
  </p>
<%end%>
If I change either erb file''s line:
<% form_tag(''/someothermodel/somemethod'')
It did swap form data between controllers.
I hope I understood your question.  I am new to ruby.
Cris
Kad Kerforn wrote:> @trainee is an instance of User class
> 
> my form partial code :
> 
> <% form_for :@trainee, :html => {:class =>
''generalform''} do |form| %>
>   <%= render :partial => "form", :object => form %>
>    <%= form.submit "Register", :class =>
''go'' %> <%= link_to
> ''Cancel'', trainees_path %>
> <% end %>
> 
> the generated html is obviously :
> <form id="new_user" class="generalform"
method="post" action="/users">
> 
> but I would like to send it to a trainee_controller  (rather than to
> user_controller... )
> 
> (don''t want to subclass, I am using roles, and a trainee is a user
> with ''trainee'' role
> 
> is it possible ?if yes, how should I proceed ?
> 
> many thanks ba
> erwin
-- 
Posted via http://www.ruby-forum.com/.
Thanks Colin...  I looked into it in parallel ... not obvious but I
found the solution (many tries.. as it''s not the
''standard'' way.. but
I''m just writing a quick app draft)
<% form_for :tutor, @tutor, :url => { :action => "create" } 
....
for  new/create records
<% form_for :tutor, @tutor, :url => tutor_path(@tutor),  .. for  edit/
update
@tutor being a User instance...
On 10 oct, 18:18, Colin Law
<clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
wrote:> 2009/10/10 Erwin <yves_duf...-ee4meeAH724@public.gmane.org>:
>
>
>
>
>
> > @trainee is an instance of User class
>
> > my form partial code :
>
> > <% form_for :@trainee, :html => {:class =>
''generalform''} do |form| %>
> >        <%= render :partial => "form", :object =>
form %>
> >         <%= form.submit "Register", :class =>
''go'' %> <%= link_to
> > ''Cancel'', trainees_path %>
> > <% end %>
>
> > the generated html is obviously :
> > <form id="new_user" class="generalform"
method="post" action="/users">
>
> > but I would like to send it to a trainee_controller  (rather than to
> > user_controller... )
>
> > (don''t want to subclass, I am using roles, and a trainee is a
user
> > with ''trainee'' role
>
> > is it possible ?if yes, how should I proceed ?
>
> Have a look at the docs for form_for, the :url option will let you do this.
>
> Colin
thanks .. got it.. see my answer to Colin.... the doc info is not obvious... I had to read between lines and test test test ...many different options to watch the generated html.... but it works well now... ( I keep the ''recipe'' in my NoteTaker ;-))) On 10 oct, 20:18, Cris Shupp <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Erwin, > > If I understand what you are trying to do then I was trying to solve a > similar but lesser problem. How to send form data from one method in a > controller to another method in the same controller Iit does seem to > work for your case though). Here is a sample erb: > > gather.html.erb > <h1>Gathering transient data</h1> > <% form_tag(''transient/show'') do %><!--sends to the show method of the > transient controller--> > <p> > <b>First Name</b><br /> > <%= text_field_tag "firstname", TransientData.firstname %> > <br/><b>Last Name</b><br /> > <%= text_field_tag "lastname", TransientData.lastname %> > <%= submit_tag "Submit" %> > </p> > <%end%> > > show.html.erb > > <h1>Gathering transient data</h1> > <% form_tag(''/transient/gather'') do%> <!--and back to gather--> > <p> > <b>First Name</b><br /> > <%= TransientData.firstname %> > <br/><b>Last Name</b><br /> > <%= TransientData.lastname %> > <%= submit_tag "Submit" %> > </p> > > <%end%> > > If I change either erb file''s line: > > <% form_tag(''/someothermodel/somemethod'') > > It did swap form data between controllers. > > I hope I understood your question. I am new to ruby. > > Cris > > > > Kad Kerforn wrote: > > @trainee is an instance of User class > > > my form partial code : > > > <% form_for :@trainee, :html => {:class => ''generalform''} do |form| %> > > <%= render :partial => "form", :object => form %> > > <%= form.submit "Register", :class => ''go'' %> <%= link_to > > ''Cancel'', trainees_path %> > > <% end %> > > > the generated html is obviously : > > <form id="new_user" class="generalform" method="post" action="/users"> > > > but I would like to send it to a trainee_controller (rather than to > > user_controller... ) > > > (don''t want to subclass, I am using roles, and a trainee is a user > > with ''trainee'' role > > > is it possible ?if yes, how should I proceed ? > > > many thanks ba > > erwin > > -- > Posted viahttp://www.ruby-forum.com/.