Compile error in ruby on rails application (error is with rails form helpers)
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 ... 开发者_StackOverflow社区 ^ /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
Try to remove =
from form line:
<% form_tag(search_path, :method => "get") do %>
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
精彩评论