Francois
Francois

Reputation: 10631

Ruby on rails form variables as array items

I have a simple form with text input and text area, but when I submit it the variables seems to be array items instead of just string values?

the form

<%= form_tag(home_kontak_path, :remote => true) do %>
<label>Jou epos adres</label>
<%= text_field(:epos, "", :placeholder => "Jou epos adres", :id => "epos", :class => "input-block-level") %>

<label>Boodskap hier</label>
<%= text_area(:boodskap, "", :rows => "5", :placeholder => "Boodskap hier...", :id => "boodskap", :class => "input-block-level") %>

<%= submit_tag "submit" %>
<% end %>

console output

Started POST "/home/kontak" for 127.0.0.1 at 2012-11-23 11:53:03 +0200
Processing by HomeController#kontak as JS
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"i+5UWaQeBu7LYGPFBNAbum+67VzyyC82JN2wMlLc/UU=", "epos"=>["text box value"], "boodskap"=>["text area value"], "commit"=>""}

what i would like it to be
instead of

"epos"=>["text box value"]

i want it to return

"epos"=>"text box value"


Update I have tried the following syntax to no avail

<%= text_field "epos", "", :placeholder => "Jou epos adres", :id => "epos", :class => "input-block-level" %>

and

<%= text_field :epos, "", :placeholder => "Jou epos adres", :id => "epos", :class => "input-block-level" %>

i still get

Started POST "/home/kontak" for 127.0.0.1 at 2012-11-23 13:34:57 +0200
Processing by HomeController#kontak as JS
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"i+5UWaQeBu7LYGPFBNAbum+67VzyyC82JN2wMlLc/UU=", "epos"=>["asd"], "boodskap"=>["asd"], "commit"=>""}

Upvotes: 1

Views: 343

Answers (2)

Francois
Francois

Reputation: 10631

Ok I have found my own problem :)

I replaced text_field with text_field_tag and text_area with text_area_tag
now it shows the correct output as sting items and not array items

Parameters: {"epos"=>"epos adr here", "boodskap"=>"boodskap here"}

Upvotes: 0

Super Engineer
Super Engineer

Reputation: 1976

Use this format instead of the above one.

<%= text_field_tag :epos, "", :placeholder => "Jou epos adres", :id => "epos", :class => "input-block-level" %>

Upvotes: 1

Related Questions