我的 Ruby 应用程序中无法显示搜索栏

I can't get a search bar to appear in my Ruby application

我有一个 Ruby 应用程序,正在尝试实现搜索功能。我有处理搜索请求的代码,但无法显示搜索栏,我已将其编码到我的 application.html.haml 中,但出现非法嵌套错误。我做错了什么?

%body  
    %header  
        .wrapper.clearfix  
            #logo= link_to "Scribble", root_path  
                <li><%= form_tag(search_path, method: :get) do %>  
                    <%= text_field_tag(:post_title, params[:post_title]) %>  
                    <%= submit_tag "Search" %>  
                <% end %>  
            %nav  
                - if user_signed_in?  
                    = link_to current_user.name, edit_user_registration_path  
                    = link_to "Add New Inspiration", new_post_path, class: "button"  
                - else  
                    = link_to "Sign in", new_user_session_path  
                    = link_to "Sign Up", new_user_registration_path, class: "button"  
    %p.notice= notice  

您在 HAML 视图中使用 ERB 语法,因此它应该是 HAML 语法而不是 ERB

.wrapper.clearfix
  = form_tag(search_path, method: :get) do
    = text_field_tag(:post_title, params[:post_title])
    = submit_tag "Search"

从第 5 行到第 9 行,你有 erb,模板的其余部分用 HAML 编写。

此代码应按预期工作

%body  
    %header  
        .wrapper.clearfix  
            #logo= link_to "Scribble", root_path  
            %li
                = form_tag(search_path, method: :get) do 
                    = text_field_tag(:post_title, params[:post_title])
                    = submit_tag "Search"
            %nav  
                - if user_signed_in?  
                    = link_to current_user.name, edit_user_registration_path  
                    = link_to "Add New Inspiration", new_post_path, class: "button"  
                - else  
                    = link_to "Sign in", new_user_session_path  
                    = link_to "Sign Up", new_user_registration_path, class: "button"  
    %p.notice= notice