Question

This is my _search_box.html.erb file

<%= form_tag "/search", :method => "get" do %>
  <%= text_field :q %> 
  <%= submit_tag 'Search' %>
<% end %>

which is rendered in search.html.erb:

'search_box' %>
<% if @products %>
    <%= render(:partial => "products") %>
<% end %>

However, I am getting an error in _search_box.html.erb, line 2:

Showing /****/app/views/catalog/_search_box.html.erb where line #2 raised:

wrong number of arguments (1 for 2)

Extracted source (around line #2):

1: <%= form_tag "/search", :method => "get" do %>
2:   <%= text_field :q %> 
3:   <%= submit_tag 'Search' %>
4: <% end %>

Waht's wrong?

Was it helpful?

Solution

It's not form_tag that's giving you the error, it's text_field. text_field is designed to be used inside form_for, not form_tag.

I think you mean to use text_field_tag instead.

text_field(object_name, method, options = {})

Returns an input tag of the “text” type tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object). Additional options on the input tag can be passed as a hash with options. These options will be tagged onto the HTML as an HTML element attribute as in the example shown.

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html

text_field_tag(name, value = nil, options = {})

Creates a standard text field; use these text fields to input smaller chunks of text like a username or a search query.

http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top