2

I'm writing a ruby on rails application, and am getting a compile error for the following code

<%= form_tag(search_path, :method => "get") do %>
<%= label_tag(:q, "Search for:") %>
<%= text_field_tag(:q) %>
<%= submit_tag("Search") %>
<% end %>

this is sample code from the ruby on rails forms guide: http://guides.rubyonrails.org/form_helpers.html

The error generated is,

compile error /Users/kmb89144/Desktop/Stoastic/app/views/application/index.html.erb:3: syntax error, unexpected ')' ...h_path, :method => "get") do ).to_s); @output_buffer.concat ... ^ /Users/kmb89144/Desktop/Stoastic/app/views/application/index.html.erb:13: syntax error, unexpected kENSURE, expecting ')' /Users/kmb89144/Desktop/Stoastic/app/views/application/index.html.erb:15: syntax error, unexpected kEND, expecting ')'

Extracted source (around line #3):

1: 

2:

3: <%= form_tag(search_path, :method => "get") do %>

4: <%= label_tag(:q, "Search for:") %>

5: <%= text_field_tag(:q) %>

6: <%= submit_tag("Search") %>

Any suggestions?

Thanks

1
  • 1
    What version of Rails do you have? Commented Dec 30, 2010 at 7:41

2 Answers 2

5

Try to remove = from form line:

<% form_tag(search_path, :method => "get") do %>
Sign up to request clarification or add additional context in comments.

Comments

0

Please use form_with, because in the new versions of Rails 5 the functions form_for and form_tag will be discontinued.

Use that:

<%= form_with(url: search_path, method: :get, local:true) do |f|%>
  <%= f.label 'Search for:' %>
  <%= f.text_field :q, id: :q %>
  <%= f.submit 'Search' %>
<% end %>

References: https://m.patrikonrails.com/rails-5-1s-form-with-vs-old-form-helpers-3a5f72a8c78a

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.