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

时间:2016-12-14 12:51:49

标签: html ruby-on-rails ruby haml

我有一个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  

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

通过第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