1

我有一个带有文本输入和文本区域的简单表单,但是当我提交它时,变量似乎是数组项,而不仅仅是字符串值?

表格

<%= 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 %>

控制台输出

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"=>""}

我希望它是什么
而不是

"epos"=>["文本框值"]

我想让它回来

"epos"=>"文本框值"


更新 我尝试了以下语法无济于事

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

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

我仍然得到

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"=>""}
4

2 回答 2

1

使用此格式而不是上述格式。

<%= text_field_tag :epos, "", :placeholder => "Jou epos adres", :id => "epos", :class => "input-block-level" %>
于 2012-11-23T10:58:05.763 回答
0

好的,我发现了自己的问题 :)

我将text_field替换为text_field_tag并将text_area替换为text_area_tag
现在它将正确的输出显示为 sting 项而不是数组项

Parameters: {"epos"=>"epos adr here", "boodskap"=>"boodskap here"}
于 2012-11-23T11:44:46.147 回答