user3447780
user3447780

Reputation: 175

undefined local variable or method `end_form_tag'

I have this code on _search_boxes.html.erb

    <%= form_tag({:action => "search"}, {:method => "get"}) %>
    <%= text_field_tag :q %>
    <%= submit_tag "Search" %>
    <%= end_form_tag %>

but the last line shows that undefined local variable or method `end_form_tag' error

Upvotes: 0

Views: 1114

Answers (5)

iiRosie1
iiRosie1

Reputation: 162

The proper code should look like this:

<%= form_tag({:action => "search"}, {:method => "get"}) do %>
<%= text_field_tag :q %>
<%= submit_tag "Search" %>
<% end %>

You shouldn't need an = in the <%= end %> the only times you use = would be when you have some ruby code to show in the application. Hope this helps!

Upvotes: 0

Pavan
Pavan

Reputation: 33542

<%end_form_tag %> works with Rails versions prior 3 and now it is deprecated.Instead use <%end%> or even just using </form> will also works.

So your should looks like this

<%= form_tag({:action => "search"}, {:method => "get"}) %>
<%= text_field_tag :q %>
<%= submit_tag "Search" %>
<% end %>

Update

you are missing a do in your form_tag and remove = in <%= end %>.It should be like this

<%= form_tag({:action => "search"}, {:method => "get"}) do %>
    <%= text_field_tag :q %>
    <%= submit_tag "Search" %>
    <% end %>

For more details,see this API

Upvotes: 2

Raghvendra Parashar
Raghvendra Parashar

Reputation: 4053

<%= form_tag('/search', method: :get) do -%>
  <%= text_field_tag 'q' %>
  <%= submit_tag 'Save' %>
<% end -%>

for more information refer ruby-doc

Upvotes: 1

Richard Peck
Richard Peck

Reputation: 76774

Just use <% end %> instead of <% end_form_tag %>.<% end_form_tag %> is now deprecated.

Upvotes: 0

Fariz Luqman
Fariz Luqman

Reputation: 914

<%= end_form_tag %> is deprecated.

Just use

<%= form_tag({:action => "search"}, {:method => "get"}) %>
<%= text_field_tag :q %>
<%= submit_tag "Search" %>
<%= end %>

Upvotes: 0

Related Questions