Forum: Ruby on Rails Help: Input of form 1 to hidden field in form 2?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
JC (Guest)
on 2006-03-29 18:47
Hi all I'm new to rails an i'm trying to build a step by step form /
process to gather data. For example:
form one:
User enters a 8 digit number
the submit button points to form 2.

form two:
the 8 digit number from form one becomes a hidden field in form 2.

The problem I have is that the entire hash from form 1 is showing up in
form two rather than just the input data.


example:

form 1:

<h1>Step 1</h1>

<%= start_form_tag :action => 'step2' %>
  <%= render :partial => 'form1' %>
  <%= submit_tag "Register Tag" %>
<%= end_form_tag %>

Here is the partial (form1):

<!--[form:tag]-->
<p>
<%= text_field 'tag', 'tag'  %></p>
<!--[eoform:tag]-->



CONTROLLER:
  def step1
    @tag = Tag.new
    render :action => 'step1'
  end

  def step2
    @newtag = (@params[:tag])
    @tag = Tag.new
    render :action => 'step2'
  end


FORM 2:
...
<input id="tag" name="tag" type="hidden" value="<%= @newtag %>" /></p>



RESULT:
If I submit 12345678 in form 1

I get "tag12345678" in form 2


FORM 2:
Source after Form 1 submit
<input id="tag" name="tag" type="hidden" value="tag12345678" /></p>

I only want the digits 12345678.
Takashi Okamoto (Guest)
on 2006-03-29 19:09
(Received via mailing list)
you're feeding the whole tag hash into @newtag. try changing in your
controller:

> CONTROLLER:
>   def step1
>     @tag = Tag.new
>     render :action => 'step1'
>   end
>
>   def step2
>     @newtag = (@params[:tag])
       @newtag = (@params[:tag][:tag])

>     @tag = Tag.new
>     render :action => 'step2'
>   end

maybe you should change the name of your text_field name to something
like tag[value]...tag[tag] is a bit confusing:

<%= text_field 'tag', 'value'  %>

-tak.
This topic is locked and can not be replied to.