2015-10-19 54 views
1

設計師給了我下面的代碼片段:複雜的標籤,以LINK_TO

 <a href="register_learner.html"> 
     <div class="service-block service-block-sea service-or"> 
      <div class="service-bg"></div> 
      <i class="icon-custom icon-color-light rounded-x fa fa-user-plus"></i> 
      <h2 class="heading-md">Register a Learner</h2> 
     </div> 
     </a> 

這我想製作成一個單一的link_to。這可能在Rails中,如果有的話,一個提示將不勝感激。

或者我看到它錯了?我試圖把div放出來,然後把link_to 'Register Learner', new learner_path放在它們中間,但它不起作用。

+1

可能的重複:http://stackoverflow.com/questions/1086360/how-do-i-wrap-link-to-around-some-html-ruby-code – brito

回答

2
在軌

你可以做到這一點像

<%= link_to "register_learner" do %> 
    <div class="service-block service-block-sea service-or"> 
     <div class="service-bg"></div> 
     <i class="icon-custom icon-color-light rounded-x fa fa-user-plus"></i> 
     <h2 class="heading-md">Register a Learner</h2> 
    </div> 
    <% end %> 

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

編輯 - 順便說一句,把div的內部使用時要皺起眉頭a標籤,但現在是可以接受的做法,只要內容中沒有交互元素。例如,不要在裏面放置另一個鏈接。