0

how can i join the ruby code with the html code? I want that the html "href" link with the path (ruby). Could somebody help me? For example: <li class="active"><a href="#">Home</a></li> , the href linked to Ruby <%= link_to "Home", root_path %> .

Ill want that my Button Home, for example is linked with the Ruby root_path.

HTML Code

>  <div class="navbar navbar-fixed-top">
>           <div class="navbar-inner">
>             <div class="container">
>               <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
>                 <span class="icon-bar"></span>
>                 <span class="icon-bar"></span>
>                 <span class="icon-bar"></span>
>               </a>
>               <a class="brand" href="#">My Workingtimes</a>
>               <div class="nav-collapse">
>                 <ul class="nav">
>                   <li class="active"><a href="#">Home</a></li>
>                   <li><a href="#about">Log In</a></li>
>                   <li><a href="#contact">Sign In</a></li>
>                 </ul>
>               </div><!--/.nav-collapse -->
>             </div>
>           </div>
>         </div>

RUBY CODE

<div id="container">

    <div id="content">
        <% if flash[:notice] %>
        <p id="notice">
            <%= flash[:notice] %>
        </p>
        <% end %>

        <% if flash[:alert] %>
        <p id= "alert">
            <%= flash[:alert] %> 
        </p>
        <% end %>
    </div>
    <div id="footer">
    <%= link_to "Home", root_path %> |
    <%= link_to "Sign In", new_user_path %> |
        <% if user_signed_in? %>
        <%= link_to "Logout", logout_path, method: :delete %> |
        <%= link_to "My Workingtimes", mytimes_path %>
        <% else %>
        <%= link_to "Login", login_path %>
        <% end %> 
        <%= yield %>
    </div>
</div>
4

1 回答 1

1

例如,您可以运行rake routes并查看root_path指向的内容。

除非您没有进行任何更改,否则它可能指向/,在这种情况下您可以拥有href = "/"

这是假设您绝对需要在HTML. 否则,我强烈建议您将其转换.html.html.erb然后使用<%= link_to "Home", root_path %>您提到的类似内容。

于 2012-05-08T07:34:08.967 回答