2

我的导航栏代码如下所示:

%header.navbar.navbar-fixed-top
  %div.navbar-inner
    %div.container
      %nav
        %ul.nav.pull-right
          - if user_signed_in?
            %li= link_to "Sign out", '#'
          - else
            %li= link_to "Sign in", '#'

我试图让我的导航栏在 Bootstrap 导航栏页面中看起来像这里显示的那样,但是我不知道如何翻译

<form class="navbar-search pull-left">
  <input type="text" class="search-query" placeholder="Search">
</form>

进入哈姆尔。我的最后一次尝试看起来像:

%header.navbar.navbar-fixed-top
  %div.navbar-inner
    %div.container
      %nav
        %ul.nav.pull-right
         %form.navbar-search
           %input.search-query
             - { :type => "text", :placeholder => "Search" }
         - if user_signed_in?
            %li= link_to "Sign out", '#'
          - else
            %li= link_to "Sign in", '#'

虽然搜索栏出现了正确的 CSS 类,但当我检查它时,我的 html 中不存在:type => "text"和部分。:placeholder => "Search"我怎样才能解决这个问题?谢谢!

== 编辑 ==

也许为了让这一点更清楚 - 我在 rails 3 应用程序中使用它,我意识到我可能应该使用form_tag,但我不确定如何继续。

4

1 回答 1

4

它应该像这样工作:

%header.navbar.navbar-fixed-top
  %nav.navbar-inner
    .container
      %ul.nav
        - if user_signed_in?
          %li= link_to "Sign out", '#'
        - else
          %li= link_to "Sign in", '#'
      = form_tag some_path, :class => "navbar-search pull-left", :method => :get do
        = text_field_tag :name, nil, :class => "search-query span3", :placeholder => "Search"

小心压痕。

I also advise you to try to start with rails app template and tutorial: http://railsapps.github.com/. As for a beginner it would be an excellent example of what and how to set up and how it should look like.

于 2012-06-02T17:58:26.907 回答