开发者

RnR using params[] getting hash when I want value

I have a web form to which I want to take a parameter from the URL and add it to the web form as a hidden field on the form.

<%= form_tag(:action => 'create') do |f| %>
    <%= text_field_tag :email,"Your email address...", :class => "text", :id => "email", :name => 'email',
        :onFocus => "change(this,'#222222'); this.value=''; this.onfocus=null;", :size => "26" %>
    <%= hidden_field_tag :ref_code, :id => 'ref_code', :name => 'ref_code', :value => params[:ref_code] %>
    <%= s开发者_如何转开发ubmit_tag "Enter To Win", :class => "button-positive submit" %>
<% end %>

If I just do a:

<%= params[:ref_code] %>

I get the value I want which is a five character alphanumeric, however when I use it in the form, I get the full hash description:

{:id=&gt;&quot;ref_code&quot;, :name=&gt;&quot;ref_code&quot;, :value=&gt;[&quot;k53e5&quot;, &quot;home&quot;, &quot;index2&quot;]}

Why? I tried .values, .to_s, and other ways of getting by key and I always get the full hash instead of just the value. What am I doing wrong? Thanks.


http://apidock.com/rails/ActionView/Helpers/FormTagHelper/hidden_field_tag
hidden_field_tag(name, value = nil, options = {})

<%= hidden_field_tag :ref_code, params[:ref_code], { :id => 'ref_code', :name => 'ref_code' } %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜